Need c++ help desperately! please read!

This is a discussion on Need c++ help desperately! please read! within the C++ Programming forums, part of the General Programming Boards category; Hey guys. I need help desperetley. I do not know where else to turn and need this turned in very ...

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

    Need c++ help desperately! please read!

    Hey guys. I need help desperetley. I do not know where else to turn and need this turned in very soon! 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. I am really having a difficult time with this program...below is some code that I have but need a lot of help and would GREATLY appreciate some help! Thanks

    Code:
    #include <iostream>
    using namespace std;
    int change(int&, int&, int&, int&, int&, int&);
    
    int main ()
    
    {
    	 
    	 
    	 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);
    
    	
    
    		
    
    		
    
    		system ("pause");
    
    			return 0;
    
    }
    
    int change (int& h, int& f, int& t, int& tenn, int& f, int& o)
    
    {
    	int hundred = 100;
    	int fifty = 50;
    	int twenty = 20;
    	int ten = 10;
    	int five = 5;
    	int one = 1;
    	int tothund;
    	int totfift;
    	int tottwent;
    	int totten;
    	int totfive;
    	int totone;
    
    	tothund = hundred / 100;
    	totfift = fifty / 50;
    	tottwent = twenty / 20;
    	totten = ten / 10;
    	totfive = five / 5;
    	totone = one /1;
    	
    	cout << tothund << endl;
    	cout << totfift << endl;
    	cout << tottwent << endl;
    	cout << totten << endl;
    	cout << totfive << endl;
    	cout << totone << endl;
    
    
    
    return  ;
    }

  2. #2
    Registered User
    Join Date
    Dec 2009
    Posts
    120
    Not one person can help me out?

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    There is no way change() compiles. The compiler should tell you that change() must return a value since you declared its return type to be int and yet do not return any value. Why does change() return an int if you never intend on using the return value or even providing one?


    I suspect modulus arithmetic will help you solve this problem. It will tell you how many of each 'bill' type 'fits' into the total desired. From that point it is a matter of subtracting that amount from the total needed and then doing the modulus on the next smaller denom. Once you reach zero you should have the least number of bill denominations that make up the total amount.
    Last edited by VirtualAce; 12-05-2009 at 01:21 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Read() problems
    By yay4rei in forum C Programming
    Replies: 2
    Last Post: 07-21-2005, 11:47 AM
  2. How can I know the actual bytes read in a file read
    By pliang in forum C++ Programming
    Replies: 1
    Last Post: 06-08-2005, 05:23 PM
  3. What Would You Use To Read User Input?
    By djwicks in forum C Programming
    Replies: 11
    Last Post: 04-05-2005, 04:32 PM
  4. Read Array pro!!Plz help!!
    By Supra in forum C Programming
    Replies: 2
    Last Post: 03-04-2002, 03:49 PM
  5. Help! Can't read decimal number
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 09-07-2001, 03:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21