It looks like you're new here. If you want to get involved, click one of these buttons!

- 141.2K All Categories
- 104.5K Programming Languages
- 6.4K Assembler Developer
- 1.9K Basic
- 39.8K C and C++
- 4.3K C#
- 7.9K Delphi and Kylix
- 4 Haskell
- 9.6K Java
- 4.1K Pascal
- 1.3K Perl
- 2K PHP
- 510 Python
- 48 Ruby
- 4.3K VB.NET
- 1.6K VBA
- 20.8K Visual Basic
- 2.6K Game programming
- 311 Console programming
- 89 DirectX Game dev
- 1 Minecraft
- 110 Newbie Game Programmers
- 2 Oculus Rift
- 8.9K Applications
- 1.8K Computer Graphics
- 726 Computer Hardware
- 3.4K Database & SQL
- 522 Electronics development
- 1.6K Matlab
- 628 Sound & Music
- 256 XML Development
- 3.3K Classifieds
- 195 Co-operative Projects
- 182 For sale
- 189 FreeLance Software City
- 1.9K Jobs Available
- 600 Jobs Wanted
- 201 Wanted
- 2.9K Microsoft .NET
- 1.7K ASP.NET
- 1.1K .NET General
- 3.2K Miscellaneous
- 3 Join the Team
- 0 User Profiles
- 349 Comments on this site
- 59 Computer Emulators
- 2K General programming
- 178 New programming languages
- 609 Off topic board
- 165 Mobile & Wireless
- 39 Android
- 124 Palm Pilot
- 335 Multimedia
- 151 Demo programming
- 184 MP3 programming
- 0 Bash scripts
- 19 Cloud Computing
- 53 FreeBSD
- 1.7K LINUX programming
- 367 MS-DOS
- 0 Shell scripting
- 320 Windows CE & Pocket PC
- 4.1K Windows programming
- 886 Software Development
- 405 Algorithms
- 68 Object Orientation
- 87 Project Management
- 90 Quality & Testing
- 235 Security
- 7.5K WEB-Development
- 1.8K Active Server Pages
- 61 AJAX
- 2 Bootstrap Themes
- 55 CGI Development
- 19 ColdFusion
- 222 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 2.2K JavaScript
- 34 JQuery
- 287 WEB Servers
- 148 WEB-Services / SOAP

tiggerzone
Posts: **13**Member

in C and C++

this is the question:

A third grade teacher at Hinsbrook Elementary School would like you to create a program that will help her students learn how to make change. The program should allow the student to enter the amount the customer owes and the amount of money the customer paid. The program should calculate and display the amount of change, as well as how many dollars, quarters, dimes, nickels, and pennnies to return to the customer. For now, you don't have to worrie about the situation where the price is greater than what the customer pays. You can always assume that the customer paid either the exact amount or more than the exact amount.

I need to code the program and this is what I have so far and from my conclusions my calculations or something is off for I get negative numbers as the change. Here is the code I did:

#include

//#include "stdafx.h"

using std:: cout;

using std:: cin;

using std:: endl;

int main()

{

//declare variables

double totalamount = 0.0;

double amountdue = 0.0;

double amountpaid= 0.0;

int DOLLARS = 0.0;

int QUARTERS = 0.0;

int DIMES = 0.0;

int NICKELS = 0.0;

int PENNIES = 0.0;

//enter input items

cout << "Enter amount due: ";

cin >> amountdue;

cout << "Enter amount paid: ";

cin >> amountpaid;

//calculate change

changeamount = amountdue - amountpaid;

DOLLARS = changeamount / 1 ;

QUARTERS = (dollars * 1) /.25 ;

DIMES = (changeamount - (dollars * 1) - (quarters * .25) / .1 );

NICKELS = (changeamount - (dollars * 1) - (quarters* .25) - (dimes* .1) / .05) ;

PENNIES = (changeamount - (dollars * 1) - (quarters * .25) - (dimes * .1) - (nickels * .05)/.01) ;

//display amount due

cout << "dollars: " << Dollars << endl;

cout << "quarters: " << Quarters << endl;

cout << "dimes: " << Dimes << endl;

cout << "nickels: " << Nickels << endl;

cout << "pennies: " <<Pennies<< endl;

return 0;

//end of main function

}

can some one help me correct this coding. Thanks

A third grade teacher at Hinsbrook Elementary School would like you to create a program that will help her students learn how to make change. The program should allow the student to enter the amount the customer owes and the amount of money the customer paid. The program should calculate and display the amount of change, as well as how many dollars, quarters, dimes, nickels, and pennnies to return to the customer. For now, you don't have to worrie about the situation where the price is greater than what the customer pays. You can always assume that the customer paid either the exact amount or more than the exact amount.

I need to code the program and this is what I have so far and from my conclusions my calculations or something is off for I get negative numbers as the change. Here is the code I did:

#include

//#include "stdafx.h"

using std:: cout;

using std:: cin;

using std:: endl;

int main()

{

//declare variables

double totalamount = 0.0;

double amountdue = 0.0;

double amountpaid= 0.0;

int DOLLARS = 0.0;

int QUARTERS = 0.0;

int DIMES = 0.0;

int NICKELS = 0.0;

int PENNIES = 0.0;

//enter input items

cout << "Enter amount due: ";

cin >> amountdue;

cout << "Enter amount paid: ";

cin >> amountpaid;

//calculate change

changeamount = amountdue - amountpaid;

DOLLARS = changeamount / 1 ;

QUARTERS = (dollars * 1) /.25 ;

DIMES = (changeamount - (dollars * 1) - (quarters * .25) / .1 );

NICKELS = (changeamount - (dollars * 1) - (quarters* .25) - (dimes* .1) / .05) ;

PENNIES = (changeamount - (dollars * 1) - (quarters * .25) - (dimes * .1) - (nickels * .05)/.01) ;

//display amount due

cout << "dollars: " << Dollars << endl;

cout << "quarters: " << Quarters << endl;

cout << "dimes: " << Dimes << endl;

cout << "nickels: " << Nickels << endl;

cout << "pennies: " <<Pennies<< endl;

return 0;

//end of main function

}

can some one help me correct this coding. Thanks

Terms of use / Privacy statement / Publisher: Lars Hagelin

Programmers Heaven articles / Programmers Heaven files / Programmers Heaven uploaded content / Programmers Heaven C Sharp ebook / Operated by CommunityHeaven LLC

© 1997-2015 Programmersheaven.com - All rights reserved.

## Comments

149Member:

: A third grade teacher at Hinsbrook Elementary School would like you to create a program that will help her students learn how to make change. The program should allow the student to enter the amount the customer owes and the amount of money the customer paid. The program should calculate and display the amount of change, as well as how many dollars, quarters, dimes, nickels, and pennnies to return to the customer. For now, you don't have to worrie about the situation where the price is greater than what the customer pays. You can always assume that the customer paid either the exact amount or more than the exact amount.

:

:

: I need to code the program and this is what I have so far and from my conclusions my calculations or something is off for I get negative numbers as the change. Here is the code I did:

:

[code]

: #include

: //#include "stdafx.h"

: using std:: cout;

: using std:: cin;

: using std:: endl;

:

: int main()

: {

:

: //declare variables

: double totalamount = 0.0;

: double amountdue = 0.0;

: double amountpaid= 0.0;

: int DOLLARS = 0.0;

: int QUARTERS = 0.0;

: int DIMES = 0.0;

: int NICKELS = 0.0;

: int PENNIES = 0.0;

:

: //enter input items

: cout << "Enter amount due: ";

: cin >> amountdue;

: cout << "Enter amount paid: ";

: cin >> amountpaid;

:

:

: //calculate change

: changeamount = amountdue - amountpaid;

: DOLLARS = changeamount / 1 ;

: QUARTERS = (dollars * 1) /.25 ;

: DIMES = (changeamount - (dollars * 1) - (quarters * .25) / .1 );

: NICKELS = (changeamount - (dollars * 1) - (quarters* .25) - (dimes* .1) / .05) ;

: PENNIES = (changeamount - (dollars * 1) - (quarters * .25) - (dimes * .1) - (nickels * .05)/.01) ;

:

:

: //display amount due

: cout << "dollars: " << Dollars << endl;

: cout << "quarters: " << Quarters << endl;

: cout << "dimes: " << Dimes << endl;

: cout << "nickels: " << Nickels << endl;

: cout << "pennies: " <<Pennies<< endl;

:

: return 0;

: //end of main function

:

: }

[/code]

:

:

: can some one help me correct this coding. Thanks

First off C is case sensitive, so decide how you want to spell your variable names...

Besides that, your math is rather off. For the quarters you probably forgot to type a part of the function, and for the other parts: Look up 'operator precedence', you should know from basic math that 1 + 2 * 3 is 7 and not 9 (=(1+2)*3), C follows these rules. (And for my personal taste: division by and multipication with 1 are nop's, so I think they look weird, but if you think it makes your program look clearer, who am I to complain?;).

I do advice you to fill in the numbers for a simple example, there's a very simple (but very important) mistake in your program, do this very, very litteraly, because, otherwise, you might miss it. (If you haven't encountered the mistake by the line that starts with 'DOLLARS = ...', start over... Somethimes you feel so stupid... Don't worry, I know exactly how you feel;)

Some further points that are not really that important (Especially when you're in a beginners class), but you might want to think about:

- You initalize your integer variables with a value of 0.0, which is a floating point value (it has a decimal point, right?)

- You assign a double-value to a integer variable in your calculation, which truncates the value (in this case exactly what you want, good idea!), which is also a very common cause for bugs in a program, if you use a cast ("intValue = (int)doubleValue;") you can show to yourself that you know and want this value to be truncated, which helps debugging when you write more complicated programs in the future.

This might look like a lot of comments, but you're doing pretty good.

Good luck and happy coding!

Pruyque

:wq

13Memberusing std:: cout;

using std:: cin;

using std:: endl;

int main()

{

//declare variables

double amountdue = 0.0;

double amountpaid= 0.0;

double DOLLARS = 0.0;

double QUARTERS = 0.0;

double DIMES = 0.0;

double NICKELS = 0.0;

double PENNIES = 0.0;

//enter input items

cout << "Enter amount due: ";

cin >> amountdue;

cout << "Enter amount paid: ";

cin >> amountpaid;

//calculate total amount

Dollars =

QUARTERS = 1 /.25 ;

DIMES = 1 - .25 / .1 ;

NICKELS = 1 - .25 - .1 / .05 ;

PENNIES = 1 - .25 - .1 - .05/.01 ;

//display change amount

cout <<"Total amount due: " <<amountdue << endl;

cout <<"Total amount paid: " <<amountpaid << endl;

return 0;

//end of main function

}

this is what I have now I know the math is still off but math isn't my best subject can you further help me on this coding so I can turn it in to my professor.

607Member ✭: using std:: cout;

: using std:: cin;

: using std:: endl;

:

: int main()

: {

:

: //declare variables

: double amountdue = 0.0;

: double amountpaid= 0.0;

: double DOLLARS = 0.0;

: double QUARTERS = 0.0;

: double DIMES = 0.0;

: double NICKELS = 0.0;

: double PENNIES = 0.0;

:

: //enter input items

: cout << "Enter amount due: ";

: cin >> amountdue;

: cout << "Enter amount paid: ";

: cin >> amountpaid;

:

:

: //calculate total amount

: Dollars =

: QUARTERS = 1 /.25 ;

: DIMES = 1 - .25 / .1 ;

: NICKELS = 1 - .25 - .1 / .05 ;

: PENNIES = 1 - .25 - .1 - .05/.01 ;

:

:

: //display change amount

: cout <<"Total amount due: " <<amountdue << endl;

: cout <<"Total amount paid: " <<amountpaid << endl;

: return 0;

: //end of main function

:

: }

:

:

: this is what I have now I know the math is still off but math isn't my best subject can you further help me on this coding so I can turn it in to my professor.

:

[blue]

Use code tags.

For the math, I would multply the changeamount by 100, and reassign

it to a int, so we can do the operations on pennies instead of dollars, basically whole numbers.

This isn't code that would fit in...use it as a guide

[/blue]

[code]

int change=(int)changeamount*100;

dollars=change/100;

change = change % 100;[blue]/*you should do this for each, you

take out the amount you've already determined and leave the remainder.

Think about the subtraction as if already you given the customer that

part of the change.(Here, the dollars) Its already given(so its subtracted), and whats left must be broken down by lesser coins...

*/

[/blue]

...

[/code]

[blue]

I hope this helps.

{2}rIng[/blue]

13Member607Member ✭:

What problem do you still have? How much have you gotten done? You can't expect anyone here to do your assignment for you, you know.

{2}rIng

13MemberWith the assignment I'm having coding problems with the calculations for the numbers come out negative digits. If you can fully complete this one code for me I will never ask you for any more help to my assignments.

This is the coding I have so far:

#include

using std:: cout;

using std:: cin;

using std:: endl;

int main()

{

//declare constant variables

double amountdue = 0.0;

double amountpaid= 0.0;

double DOLLARS = 0.0;

double QUARTERS = 0.0;

double DIMES = 0.0;

double NICKELS = 0.0;

double PENNIES = 0.0;

//enter input items

cout << "Enter amount due: ";

cin >> amountdue;

cout << "Enter amount paid: ";

cin >> amountpaid;

//calculate change amount

DOLLARS = (amountdue / 1);

QUARTERS = (amountdue - (DOLLARS * 1) / .25);

DIMES = (amountdue - (DOLLARS * 1) - (QUARTERS * .25) / .1);

NICKELS = (amountdue - (DOLLARS * 1) - (QUARTERS * .25) - (DIMES * .1) / .05);

PENNIES = (amountdue - (DOLLARS * 1) - (QUARTERS * .25) - (DIMES * .1) - (NICKELS * .05) / .01);

//display change amount

cout <<"Total amount due: " <<amountdue << endl;

cout <<"Total amount paid: " <<amountpaid << endl;

return 0;

//end of main function

}

But somewhere in the coding is wrong can you help me?

607Member ✭: I understand all that but I never done coding before in my entire life and this C++ stuff is very new to me and I'm having a hard time understanding it. The professor himself isn't helping me as much as he should be and that is why I'm asking you all for help.

:

:

: With the assignment I'm having coding problems with the calculations for the numbers come out negative digits. If you can fully complete this one code for me I will never ask you for any more help to my assignments.

:

:

: This is the coding I have so far:

:

: #include

: using std:: cout;

: using std:: cin;

: using std:: endl;

:

: int main()

: {

:

: //declare constant variables

: double amountdue = 0.0;

: double amountpaid= 0.0;

: double DOLLARS = 0.0;

: double QUARTERS = 0.0;

: double DIMES = 0.0;

: double NICKELS = 0.0;

: double PENNIES = 0.0;

:

: //enter input items

: cout << "Enter amount due: ";

: cin >> amountdue;

: cout << "Enter amount paid: ";

: cin >> amountpaid;

:

:

: //calculate change amount

: DOLLARS = (amountdue / 1);

: QUARTERS = (amountdue - (DOLLARS * 1) / .25);

: DIMES = (amountdue - (DOLLARS * 1) - (QUARTERS * .25) / .1);

: NICKELS = (amountdue - (DOLLARS * 1) - (QUARTERS * .25) - (DIMES * .1) / .05);

: PENNIES = (amountdue - (DOLLARS * 1) - (QUARTERS * .25) - (DIMES * .1) - (NICKELS * .05) / .01);

:

:

: //display change amount

: cout <<"Total amount due: " <<amountdue << endl;

: cout <<"Total amount paid: " <<amountpaid << endl;

: return 0;

: //end of main function

: }

:

: But somewhere in the coding is wrong can you help me?

:

:

I guess I confused you a bit, or, idk. You are performing calculations with the amount due, and you don't even output/display the dollars, the quarters, whatever...

You need to perform calculations on the change, which is amountDue - amountPaid, just as you did before...

First of all, any number divided by 1 is that number, just as any number times one is that number. Thus, trying to get the dollars by dividing the change by 1 isn't going to help you. This is a C++ program you're making, right? Well, try to

#include math.h

and then call floor() on the change, like

DOLLARS = floor(changeAmount);

It will return the number of dollars, for sure.

Now, after that, you should minus the dollars from the change, AND ASSIGN THAT TO CHANGE, thus, for the next coins, what part of the change is already in dollars isn't accidentally used. Understand?

Then, work on as usual, divide by .25, then .10, then .05, but be sure to minus the each coin's number from the change after you determine that coin's number.

And don't forget to output the coin's numbers. It would be sad if you do all that, but then the output's not even there...

I have to leave somewhere in 45 min. I keep checking to see if you need anymore help.

{2}rIng

1Member: :

: : A third grade teacher at Hinsbrook Elementary School would like you to create a program that will help her students learn how to make change. The program should allow the student to enter the amount the customer owes and the amount of money the customer paid. The program should calculate and display the amount of change, as well as how many dollars, quarters, dimes, nickels, and pennnies to return to the customer. For now, you don't have to worrie about the situation where the price is greater than what the customer pays. You can always assume that the customer paid either the exact amount or more than the exact amount.

: :

: :

: : I need to code the program and this is what I have so far and from my conclusions my calculations or something is off for I get negative numbers as the change. Here is the code I did:

: :

: [code]:

: : #include

: : //#include "stdafx.h"

: : using std:: cout;

: : using std:: cin;

: : using std:: endl;

: :

: : int main()

: : {

: :

: : //declare variables

: : double totalamount = 0.0;

: : double amountdue = 0.0;

: : double amountpaid= 0.0;

: : int DOLLARS = 0.0;

: : int QUARTERS = 0.0;

: : int DIMES = 0.0;

: : int NICKELS = 0.0;

: : int PENNIES = 0.0;

: :

: : //enter input items

: : cout << "Enter amount due: ";

: : cin >> amountdue;

: : cout << "Enter amount paid: ";

: : cin >> amountpaid;

: :

: :

: : //calculate change

: : changeamount = amountdue - amountpaid;

: : DOLLARS = changeamount / 1 ;

: : QUARTERS = (dollars * 1) /.25 ;

: : DIMES = (changeamount - (dollars * 1) - (quarters * .25) / .1 );

: : NICKELS = (changeamount - (dollars * 1) - (quarters* .25) - (dimes* .1) / .05) ;

: : PENNIES = (changeamount - (dollars * 1) - (quarters * .25) - (dimes * .1) - (nickels * .05)/.01) ;

: :

: :

: : //display amount due

: : cout << "dollars: " << Dollars << endl;

: : cout << "quarters: " << Quarters << endl;

: : cout << "dimes: " << Dimes << endl;

: : cout << "nickels: " << Nickels << endl;

: : cout << "pennies: " <<Pennies<< endl;

: :

: : return 0;

: : //end of main function

: :

: : }

: [/code]:

: :

: :

: : can some one help me correct this coding. Thanks

:

: First off C is case sensitive, so decide how you want to spell your

: variable names...

:

: Besides that, your math is rather off. For the quarters you probably

: forgot to type a part of the function, and for the other parts: Look

: up 'operator precedence', you should know from basic math that 1 + 2

: * 3 is 7 and not 9 (=(1+2)*3), C follows these rules. (And for my

: personal taste: division by and multipication with 1 are nop's, so I

: think they look weird, but if you think it makes your program look

: clearer, who am I to complain?;).

:

: I do advice you to fill in the numbers for a simple example, there's

: a very simple (but very important) mistake in your program, do this

: very, very litteraly, because, otherwise, you might miss it. (If you

: haven't encountered the mistake by the line that starts with

: 'DOLLARS = ...', start over... Somethimes you feel so stupid...

: Don't worry, I know exactly how you feel;)

:

: Some further points that are not really that important (Especially

: when you're in a beginners class), but you might want to think about:

: - You initalize your integer variables with a value of 0.0, which is

: a floating point value (it has a decimal point, right?)

: - You assign a double-value to a integer variable in your

: calculation, which truncates the value (in this case exactly what

: you want, good idea!), which is also a very common cause for bugs in

: a program, if you use a cast ("intValue = (int)doubleValue;") you

: can show to yourself that you know and want this value to be

: truncated, which helps debugging when you write more complicated

: programs in the future.

:

: This might look like a lot of comments, but you're doing pretty good.

: Good luck and happy coding!

:

: Pruyque

: :wq

:

I am on the same problem, but I have to use if else statements. How can I use that?

6,519Member1. The types of change should be inside the array and they must be sorted in descending order, for example:

[/color]

[code]

int changeVector [] =

{

1000, [color=Green]// $10 bill in cents[/color]

500, [color=Green]// $5 bill in cents[/color]

100, [color=Green]// $1 bill in cents[/color]

25, [color=Green]// a quarter[/color]

10, [color=Green]// a dime[/color]

5, [color=Green]// a nickel[/color]

1 [color=Green]// a penny[/color]

};

[/code]

[color=Blue]Great, now we need another array, where we could count the change (how many of each type we need to give.) and here it is, all items are set to zeroes:[/color]

[code]

int countVector [7] = {0}; [color=Green]// size (7) matches the 1st array[/color]

[/code]

[color=Blue]After this all needs to be done is SUBTRACT from the change the amount from array #1 and count these items in array #2. This loop continues until zero is left instead of the change amount:

[/color]

[code]

[color=Green]//

// 13.73 to give to customer

//[/color]

int changeDollars = 13;

int changeCents = 73;

[color=Green]//

// Convert all to cents:

//[/color]

int amountCents = 100*changeDollars + changeCents;

[color=Green]//

// Loop for all items in the array(s)

//[/color]

for (int i=0; (i<7) && (amountCents > 0); i++)

{

[color=Green]//

// Subtract only if it will not result in negative value

// When negative value is a result - move to next coin type

//[/color]

while (amountCents > 0)

{

if ((amountCents - changeVector [i]) < 0) break;

[color=Green]//

// Make one step

//[/color]

amountCents -= changeVector [i];

++(countVector [i]);

}

}

[color=Green]//

// Print results

//[/color]

for (int idx=0; idx<7; idx++)

{

if (countVector [i])

{

printf ("

%d items of %d cents", countVector [idx], changeVector [idx]);

}

}

[/code]