我是一个绝对的C++新手,似乎所以我需要一些帮助。 我正在努力制定一个程序,它决定了需要支付某些东西的最少金币数量。C++整数不会改变
例:你告诉它你要支付2,50所以说,你需要一个2€硬币0.50€硬币(而不是这样的:你需要5个* 0.50€硬币)
所以我方法是给它的价格,然后它会运行一个时间循环为每个硬币测试硬币是否仍然适合价值。 我的问题是,我不能改变我的整数,我敢肯定它的一些非常简单的错误,我只是不知道。
代码(即计算刚好功能):
int Rechner() {
int Betrag;
int ZweiEuro = 0;
int EinEuro = 0;
int FuenfzigCent = 0;
int ZwanzigCent = 0;
int ZehnCent = 0;
int FuenfCent = 0;
int ZweiCent = 0;
int EinCent = 0;
cin >> Betrag;
cout << "Die kleinse Menga an Muenzen um ihren Betrag zu bezahlen ist:" << endl << endl << endl;
ZweiEuro + 2;
cout << "2.00 = " << ZweiEuro << endl;
cout << "1.00 = " << EinEuro << endl;
cout << "0.50 = " << FuenfzigCent << endl;
cout << "0.20 = " << ZwanzigCent << endl;
cout << "0.10 = " << ZehnCent << endl;
cout << "0.05 = " << FuenfCent << endl;
cout << "0.02 = " << ZweiCent << endl;
cout << "0.01 = " << EinCent << endl << endl << endl << endl << endl << endl;
cout << "[Enter] druecken um zu beenden.";
cin.sync();
cin.get();
return 0;
所以这并不具有任何while循环,因为他们不工作,就像ZweiEuro + 2并没有改变任何东西。 无论我添加或不添加结果,结果总是保持为0。
林相当肯定我可以很容易地完成这个程序,如果我后面改变我的变量的上帝该死的价值观。 感谢您的帮助。
'ZweiEuro + 2;'产生一个结果,但不存储它。您需要将结果分配给一个变量。试试'ZweiEuro = ZweiEuro + 2;'或'ZweiEuro + = 2;'。 –
它就像在初始化中一样:'ZweiEuro = 0;',那里你也没有写'0',并希望编译器知道该怎么做;} – user463035818
这是一个谜语:说出来大声“比我左手拿着的还多2欧元硬币”。你现在握着你的左手多少钱? – molbdnilo