1.我正在尝试模拟收银员登记册,这是一个互联网上的代码,应该有效,但QT一直告诉我,美元,宿舍,角钱,镍币等等。便士是未申报的身份证明者。没有正确地在底部声明它们?
#include <iostream>
using namespace std;
void printChange(int&, int&, int&, int&, int&);
void findCoins (int&, int&, int&, int&, int&);
int main ()
{
double price;
double payment;
char answer ='y';
while(answer == 'y')
{
cout<<"Enter price of an item: "<<endl;
cin>>price;
cout<<"Enter payment from customer: "<<endl;
cin>>payment;
double change = payment - price;
dollars = change;
change = change * 100;
int coins = change - dollars * 100;
findCoins(coins, quarters, dimes, nickels, pennies);
printChange(dollars, quarters, dimes, nickels, pennies);
cout <<"Do you have another transaction?";
cin >>answer;
}
cout<<"Thanks for shopping at Albertsons!"<<endl;
return 0;
}
void printChange(int& dol, int& q, int& d, int& n, int& p)
{
cout<<"dollars "<<dol<<endl;
cout<<"quarters: "<<q<<endl;
cout<<"dimes: " <<d<<endl;
cout<<"nickels: " <<n<<endl;
cout<<"pennies: " <<p<<endl;
}
void findCoins(int& coins, int& quarters, int& dimes,
int& nickels, int& pennies)
{
quarters = coins/25;
dimes = coins % 25 / 10;
nickels = coins % 25 % 10 / 5;
pennies = coins % 25 & 10 % 5;
}
答案 0 :(得分:1)
要用c ++声明变量,你需要
TYPE name;
或
TYPE name = expession;
。
它的价格是double price;
,但不是美元和其他价格。