因此,這是問題.......乘以來自用戶的輸入將在C#
上下文代碼:
你淋浴的時間越長,你可以使用更多的水。但是多少?即使你有一個「低流量」噴頭,你的噴頭每分鐘可以吐出1.5加侖的水。一加侖是128盎司,所以淋浴吐出每分鐘1.5×128 = 192盎司的水。一瓶典型的水可能是16盎司。因此,進行1分鐘的淋浴就類似於使用192÷16 = 12瓶水。進行10分鐘的淋浴就像使用120瓶水。這些數字有助於瞭解淋浴中用水的數量! 在〜/ workspace/pset1目錄下的一個名爲water.c的文件中寫入一個程序,該程序在幾分鐘內提示用戶輸入其淋浴的長度(作爲正整數),然後打印相當數量的每個樣本輸出的水(作爲一個整數),其中帶下劃線的文本代表一些用戶的輸入。
用戶名@ ide50:〜/工作區/ PSET1 $ ./water 分鐘:10個 瓶:120 爲簡單起見,可以假設用戶將輸入一個正整數,因此無需用於錯誤校驗(或任何循環)這次!而且不必擔心溢出!
我當前的代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace console_water
{
class water_amount
{
static void Main(string[] args)
{
/*variable decleration*/
int multiply, divide;
int userInput = Console.Read();
multiply = 192;
divide = 16;
/*getting user input*/
Console.WriteLine("Length of shower in minutes:");
Console.Read();
userInput = multiply/divide;
Console.WriteLine("The amount of water used is:" + userInput);
}
}
}
但它不工作。
另一個問題使用'Console.Read()'不正確。 – crashmstr
很酷。什麼不工作,但?你到底在想什麼?認真思考一下在這裏幫助你的人。我們不會閱讀頭腦或類似的東西。給我們儘可能多的信息,但沒有更多(這是什麼大規模的介紹?)。 – async
這是非常錯誤的。在提示用戶之前,你得到一個*字符代碼*,然後得到另一個被丟棄的*字符代碼,然後你只用整數除以兩個整數。 – crashmstr