Change Conversion Homework Help

This is a discussion on Change Conversion Homework Help within the C++ Programming forums, part of the General Programming Boards category; Hi, I have an assignment which have 10 questions and I managed to do 9 of them. Question #6 has ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    2

    Change Conversion Homework Help

    Hi, I have an assignment which have 10 questions and I managed to do 9 of them. Question #6 has 2 parts to it. I managed to finish part a, but can't get part b to work. Please give me some assistance - thank you all in advance.

    6. a. Write a program for a bank that allows the user to enter an amount of money in cents. Display the number of whole dollars the bank will give the customer in exchange. This is the solution I was able to compile

    Code:
    #include<iostream>
    using namespace std;
    
    int main()
    {
    
    	int cents = 0;
    	int dollar = 0;
    	cout << "Please enter the amount of money in cents:" << endl;
    	cin >> cents; 
    	dollar = cents / 100;
    	cout << "the whole dollars amount in exchange is: " << dollar << endl << endl;
    
    system("pause");
    return 0;
    
    }
    Part B is difficult for me:

    b. Modify the program in 6a so that, in addition to the cents, the user enters the denomination of the coin to which to convert the pennies, such as 5 for nickels or 25 for quarters.

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    money = cents / 25;
    if cents is 100 then you will get 4 quarters as expected.

    So you will have to have the user input the denomination...

    cin >> denomination;

    then

    money = cents / denomination.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    2
    Thanks, that worked. I guessed I overcomplicated things and tried to define a variable for nickel or quarters. Even though the code did work, I don't think my output sentence is correct, what do you think?

    cout "The conversion amount is: <--- should I reword this?

    Code:
    #include<iostream>
    using namespace std;
    
    int main()
    {
    
    	int cents = 0;
    	int dollar = 0;
    	int denomination = 0;
    	int conversion = 0;
    	cout << "Please enter the amount of money in cents:" << endl;
    	cin >> cents; 
    		cout << "Please enter the conversion in 5(nickels) or 25(quarters):" << endl;
    	cin >> denomination;
    	dollar = cents / 100;
    	conversion = cents / denomination;
    	cout << "The whole dollars amount in exchange is: " << dollar << endl << endl;
    	cout << "The conversion amount is: " << conversion << endl << endl;
    
    system("pause");
    return 0;
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Currency Conversion problem
    By Rich Whitehead in forum C Programming
    Replies: 2
    Last Post: 09-17-2007, 12:40 PM
  2. Do I have a scanf problem?
    By AQWst in forum C Programming
    Replies: 2
    Last Post: 11-26-2004, 05:18 PM
  3. Creation of Menu problem
    By AQWst in forum C Programming
    Replies: 8
    Last Post: 11-24-2004, 08:44 PM
  4. Replies: 2
    Last Post: 11-08-2002, 02:22 AM
  5. Replies: 2
    Last Post: 09-04-2001, 02:12 PM

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