我希望用戶輸入一個數字,但如果它低於零,我想顯示一條錯誤消息,然後循環並要求用戶輸入另一個數字。這是我目前的代碼。請幫助我已經與下面的if語句非常混淆
// this determines what the loop does.
for (int CustPos = 0; CustPos < LineNum; CustPos = CustPos + 1)
{
// this asks the user to enter the sales figures
Console.Write("enter sales figures for" + customer[CustPos] + " ");
// this is user's input is read in and stored.
sales_figures[CustPos] = Double.Parse(Console.ReadLine());
if (sales_figures[CustPos] < MIN_SALES_FIGURE) //True - continue
{
Console.WriteLine("");
Console.WriteLine("entry invalid");
Console.WriteLine("enter another value");
}
else//FALSE -> Go back to start of loop
{
Console.WriteLine("");
}
//this section displays the cust name, sales figure 70/30.
Console.WriteLine(" ");
fee_payable[CustPos] = (sales_figures[CustPos]/100.0)
* licence_fee_in_percent[CustPos];
Console.WriteLine(customer[CustPos] +
" ----------- " + fee_payable[CustPos]);
Console.WriteLine("Licence fee to be paid in GBP is :" +
fee_payable[CustPos]);
seventy_percent_value = ((fee_payable[CustPos]/10.0) * 7);
Console.WriteLine("70 percent of this fee is" +
seventy_percent_value);
thirty_percent_value = ((fee_payable[CustPos]/10.0) * 3);
Console.WriteLine("30 percent of this fee is" +
thirty_percent_value);
Console.WriteLine(" ");
}
。請幫助所有建議將不勝感激!
感謝
評論像'//這決定了循環does'是完全無用的。 ''循環遍歷文檔中的所有客戶'對未來的維護者來說會更有用。 – roufamatic 2010-12-16 14:31:53
任何人都會這樣做:沒有理由:它被問到的很清楚,這是一個完全合法的問題。也@Banang,你問這是否是功課嗎?這可能是因爲斯蒂芬從一本書中解決問題,所以他可以自己學習編程。 – Crisfole 2010-12-16 14:35:54
@Cpfohl,不,我沒問斯蒂芬是否是功課,你說得對,我應該這樣做。 @Stephen,這是功課嗎?如果是的話,沒關係,但如果沒有,告訴我,我會刪除我放在那裏的作業標籤。對不起,在我把它放在那裏之前不要問你。爲了記錄,我同意Cpfohl這個問題不應該得到一票否決票,這足以說明和比這裏的許多第一次問題風格問題更好。 – 2010-12-16 14:38:54