程序提示基本上要求一个程序,您必须从该人那里获得两个输入:时间(基于一个军事时间,即 1800 是下午 6 点)和通话时间。然后,您获取这两个输入并使用布尔 if then 和 else 语句,应用折扣,然后获得净金额。这是我的代码:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{ // some user variables that need inputing based on their call
int starttime;
int minutes;
const float tax = 0.04;
const float flatrate = 0.35;
const float mindiscount = 0.15;
const float timediscount = 0.5;
float callrate = float (minutes * flatrate); // the standard call rate stored in a variable.
float gross; // the gross cost before discount
float net; // the net cost
cout << "enter start time: " << endl;
cin >> starttime;
if (starttime > 2499) // a check put inplace so someone doesn't enter an invalid time integer
{cout << "You entered an invalid time. Should only be based on the 24 hour clock " << endl;
return 1;}
cout << "enter total minutes: " << endl;
cin >> minutes;
gross = callrate;
cout << "gross cost: " << gross << setprecision(2) << endl;
{if ((minutes < 60 ) && (starttime < 1800 && starttime > 800)) // if no discounts are made, this is the final price before tax
net = gross;
else if (starttime > 1800 || starttime < 800) // if the call is between 6:00 PM and 8:00 AM, it gets a 50% discount
net = gross - (gross * timediscount);}
if (minutes > 60 ) // if the call lasted longer than 60 minutes, it gets a 15% discount
net = net - (net * mindiscount);
cout << "net cost: " << float (net + (net * tax)) << setprecision(2) << endl; // the final net cost with the 4% tax added.
return 0;
}
我不断得到一个疯狂的输出,例如:
enter start time:
1400
enter total minutes:
40
gross cost: 802795
net cost: 8.3e+005
Process returned 0 (0x0) execution time : 3.740 s
Press any key to continue.
当甚至总成本应该是基于分钟* 0.35(每分钟35美分)的非常基本的小数字但显示为802795时。我在这里做错了什么?