-3
#include <iostream>
using namespace std;
void compute_coins(int change, int quarters, int dimes, int nickels, int pennies);
void output(int quarters, int dimes, int nickels, int pennies);
int main()
{
int change, quarters, dimes, nickels, pennies;
char again = 'y';
cout << "Welcome to the change dispenser!\n";
while(again == 'y'){//Creating loop to allow the user to repeat the process
cout << "Please enter the amount of cents that you have given between 1 and 99\n";
cin >> change;
while((change < 0) || (change >100)){//Making a loop to make sure a valid number is inputed
cout << "Error: Sorry you have entered a invalid number, please try again:";
cin >> change;
}
cout << change << " Cents can be given as: " << endl;
compute_coins(change, quarters, dimes, nickels, pennies);
output(quarters, dimes, nickels, pennies);
cout << "Would you like to enter more change into the change dispenser? y/n\n";//prompts the user to repeat this process
cin >> again;
}
return 0;
}
void compute_coins(int change, int quarters, int dimes, int nickels, int pennies) {//calculation to find out the amount of change given for the amount inpuied
using namespace std;
quarters = change/25;
change = change % 25;
dimes = change/10;
change = change % 10;
nickels = change/5;
change = change % 5;
pennies = change;
return ;
}
void output(int quarters, int dimes, int nickels, int pennies){
using namespace std;
cout << "Quarters = " << quarters << endl;
cout << "dimes = " << dimes << endl;
cout << "nickels = " << nickels << endl;
cout << "pennies = " << pennies << endl;
}
对不起,代码没有转移好,我对这个网站仍然很新。但是,我在季度,硬币,镍币和便士上得到了疯狂的数字。我这样做一次了,它的工作很好,但我没有用空洞的功能,所以我不得不重做,我搞砸自己了,我被卡住。任何帮助感激!void函数数学错误
C++是通过按值,除非指定的参考。 – chris
什么*具体*会出错?你到目前为止已经尝试了哪些*具体内容?我们很乐意帮忙,但没有一些指导它为我们解答你的问题很难。你能否用更多的细节更新你的问题? – templatetypedef
你的编译器能够提供有用的警告,如果你让它:http://coliru.stacked-crooked.com/a/6449ef3601fb9ef4 – chris