c++ - void function Math error -


#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 change dispenser!\n";    while(again == 'y'){//creating loop allow user repeat process     cout << "please enter amount of cents have given between 1 , 99\n";     cin >> change;     while((change < 0) || (change >100)){//making loop make sure valid number             inputed         cout << "error: sorry have entered invalid number, please try again:";         cin >> change;     }     cout << change << " cents can given as: " << endl;     compute_coins(change, quarters, dimes, nickels, pennies);     output(quarters, dimes, nickels, pennies);      cout << "would enter more change change dispenser?  y/n\n";//prompts user repeat process     cin >> again;   }   return 0; }   void compute_coins(int change, int quarters, int dimes, int nickels, int pennies) {//calculation find out amount of change given 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; } 

sorry code didn't transfer , i'm pretty new site still. but, getting crazy numbers outcome on quarters, dimes, nickels, , pennies. did once , worked fine didn't use void functions, had redo , messed myself , i'm stuck. appreciated!

void compute_coins(int change, int quarters, int dimes, int nickels, int pennies); 

this means take in copy of values pass function. hence whatever within function won`t have effect on actual values pass in.

void compute_coins(int &change, int &quarters, int &dimes, int &nickels, int &pennies); 

this means give actual variables, not copy. whatever changes on parameters done on variables pass in.

look refences , pointers.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -