#include <cmath>
#include <iostream>
#include <string>
using namespace std;
const float DESSERT_PRICE = 4.50;
const float TAX_RATE = 0.07;
const float GRATUITY = 0.15;
const float COST_ADULT = 12.75;
const float COST_CHILD = 7.65;
const float COST_DESERT = 3.00;
int readinput(string, int, int, int, float, float);
float mult_args(float, float);
float add_args(float,float);
int main()
{
string name;
int Adult, Child, Dessert;
float Room_Fee, Deposit;
float Adult_Cost,Child_Cost, Desert_Cost,
Food_Cost,Tips,Taxes,Total_Bill,Balance;
name = readinput(name,Adult,Child,Dessert,Room_Fee,Deposit);
Adult_Cost = mult_args(COST_ADULT, Adult);
cout << Adult_Cost;
}
int readinput(string name, int Adult, int Child, int Dessert, float Room_Fee, float Deposit)
{
cout << "\t\t\tCustomers Name : ";getline(cin,name);
cout << "\t\t\t Number of Adults : ";cin>>Adult;
cout << "\t\t\t Number of Children : ";cin >> Child;
cout << "\t\t Number of Desserts : ";cin >> Dessert;
cout << "\t\t\t Room Fee : ";cin >> Room_Fee;
cout << "\t\t\t Deposit: ";cin >> Deposit;
}
float mult_args(float left, float right)
{
return left * right;
}
float add_args(float left,float right)
{
return left + right;
}
问题是成人总成本的打印只显示零需要它显示每个成人的成本乘以读取输入中的输入值hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhelp
答案 0 :(得分:0)
您的readInput
函数正在使用传递给它的变量副本:
int readinput(string name, int Adult, int Child, int Dessert, float Room_Fee, float Deposit)
我建议通过引用传递,以便您可以修改传递的变量:
int readinput(string& name, int& Adult, int& Child, int& Dessert, float& Room_Fee, float& Deposit)
另一个问题是,您在声明中声明该函数返回int
但该函数的代码中没有return
语句。函数不必返回值。您可以将它们声明为返回void
。
此外,将编译器的警告级别设置为最大值。编译器应该让你知道变量是“已设置但未使用”,这让你知道出了什么问题,并检查你的代码。