所以我的程序打算无限次运行,直到用户输入 -999。使用此当前设置,输入任何数字时发生的所有事情都是它喷出所有文本并忽略输入的任何内容。
static void Main(string[] args)
{
//Local Variable Declaration//
const double rate1 = 10;
const double rate2 = 3;
const double maxCharge = 50;
double charge;
int hoursRented;
while (true)
{
Console.WriteLine("Enter number of hours (-999 to quit) : ");
hoursRented = Console.Read();
if (hoursRented == -999)
break;
else
if (hoursRented <= 3)
{
charge = hoursRented * rate1;
}
else
{
charge = (3 * rate1) + ((hoursRented - 3) * rate2);
}
if (charge > maxCharge)
{
charge = maxCharge;
}
Console.WriteLine("Are you a member? (Y/N) : ");
string memberStatus = Console.ReadLine();
string upperstring = memberStatus.ToUpper();
if (memberStatus.Equals("Y"))
{
charge = charge - (charge * 1 / 10);
}
double TotalCharge = +charge;
Console.WriteLine("Customer Charge : {0} Total Charge To Date {1} : ", charge, TotalCharge);
}
}
}
}
相关分类