Thread: Runtime erros

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    120

    Runtime erros

    I am writing a program that accepts a value of money (an even integer value) and tells you the least amount of hundred dollar bills, fifties, twenties, tens, fives, and ones that it will take to make that total. (Example, i enter an amount of $150 and it tells me that i have 1 one hundred dollar bill and 1 fifty dollar bill) . To do this i am writing my own function named change () and am using reference parameters. It will run but I don't know what to put in the cout statements.

    When I put- hu, fi, tw, tn, fiv, on ; in the cout statements is says runtime error for all of them and tells men Theyre being used without being initialized. ?

    Code:
    #include <iostream>
    using namespace std;
    int change(int&, int&, int&, int&, int&, int&);
    
    int main ()
    
    {
    	int hu;
    	int fi;
    	int tw;
    	int tn;
    	int fiv;
    	int on;
    	
    	 
    	 int money;
    
    		cout << "How much money do you have?\n";
    		cin >> money;
    
    	int change (int hund, int fift, int twent, int ten, int five, int one);
    		
    	cout << " " << endl;
    	cout << " " << endl;
    	cout << " " << endl;
    	cout << " " << endl;
    	cout << " " << endl;
    	cout << " " << endl;
    
    	
    
    		
    
    		
    
    		system ("pause");
    
    		return 0;
    
    }
    int change (int money, int& hu, int& fi, int& tw, int& tn, int& fiv, int& on)
    
    
    {
    	
    	
      hu = money / 100;        
      money %= 100;             
      fi = money / 50;
      money %= 50;            
      tw = money / 20;
      money %= 20;
      tn = money / 10;
      money %= 10;
      fiv = money / 5;
      money %= 5;
      on = money / 1;
      money %= 1;
    	
    return hu, fi, tw, tn, fiv, on ;
     
    }

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    You define the function to accept 6 arguments as
    Code:
    int change(int&, int&, int&, int&, int&, int&);
    then you implement the function with 7 arguments as
    Code:
    int change (int money, int& hu, int& fi, int& tw, int& tn, int& fiv, int& on)
    pick one and stick with it!

    Code:
    return hu, fi, tw, tn, fiv, on ;
    A function can only return one value, so choose just one to return based on what the function is even doing. If you pass all of the arguments by reference, then you could change it to a "void" function instead of "int", so you dont have to return anything.

    Code:
    int change (int hund, int fift, int twent, int ten, int five, int one);
    This isnt how you call a function. Do something like this instead (of course using your actual variables "hu", "fi", etc)
    Code:
    int myResult = change( myArg1, myArg2, etc);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Runtime formation and execution at runtime
    By Soham in forum C Programming
    Replies: 17
    Last Post: 08-27-2008, 08:45 AM
  2. Creating controls in runtime
    By starcatcher in forum C++ Programming
    Replies: 4
    Last Post: 03-27-2008, 05:29 PM
  3. link with C runtime library
    By George2 in forum C++ Programming
    Replies: 26
    Last Post: 02-05-2008, 01:56 AM
  4. Visual Studio and .Net Runtime Framework dependency
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 08-08-2007, 07:52 AM
  5. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM