【发布时间】:2017-09-16 05:01:39
【问题描述】:
我正在尝试编写一个程序来计算在某家酒店租用房间的成本。该程序会询问租金、房间的预订天数以及销售税。我应该执行 if 语句,以便根据房间出租的时间和房间的出租方式计算给出的折扣。当我尝试设置将使用什么折扣的参数时,我不断收到一条错误消息,说“预期的主要表达式 __”随着我在第 45 - 51 行使用的每个表达式而变化。
#include <iostream>
using namespace std;
int main()
{
int Reason;
double Rent, totRent;
double SalesTax, calcST;
double TimeDiscount, totDiscount;
int numRooms;
int RentTime;
int tenRooms, twentyRooms, thirtyRooms;
int tenTotal, twentyTotal, thirtyTotal, RegularPricing;
cout << "How much is the cost of renting a room: " << endl;
cin >> Rent;
cout << "Are you staying for a special reason i.e. wedding/conference: " << endl;
cin >> Reason;
cout << "How many days are the rooms going to be booked " << endl;
cin >> RentTime;
cout << "What is the sales tax: " << endl;
cin >> SalesTax;
SalesTax = Rent * SalesTax;
calcST = Rent + SalesTax;
totRent = (Rent * numRooms) + RentTime;
if (Reason = 1)
{
cout << "How many are rooms going to be booked: " << endl;
cin >> numRooms;
}
if (RentTime >= 3)
{
TimeDiscount = .05 * Rent;
totDiscount = Rent + TimeDiscount;
}
if (numRooms >= 10)
{
tenRooms = Rent * .10;
tenTotal = (totRent + calcST) - (tenRooms + totDiscount);
cout << "Your total fee is: $" << tenTotal << endl;
}
if (numRooms >= 11 && <= 20) //45
{
twentyRooms = Rent * .20 * SalesTax * TimeDiscount;
twentyTotal = (totRent + calcST) - (twentyRooms + totDiscount);
cout << "Your total fee is: $" << twentyTotal << endl;
}
if (numRooms >= 21 && >= 30 && >> 30) //51
{
thirtyRooms = Rent * .30 + SalesTax + TimeDiscount;
thirtyTotal = (totRent + calcST) - (thirtyRooms + totDiscount);
cout << "Your total fee is: $" << thirtyRooms << endl;
}
else
{
RegularPricing = Rent * RentTime + SalesTax;
cout << "Your Total Fee is: $" << RegularPricing << endl;
}
cout << "The cost of renting one room is: $" << Rent << endl;
cout << "Number of rooms booked : " << numRooms << endl;
cout << "Days booked: " << RentTime << endl;
cout << "The sales tax is: $" << calcST << endl;
return 0;
}
【问题讨论】:
-
不要猜测语法,read a good book
-
^尤其是,了解什么是表达式。
标签: c++ if-statement