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

- 140.6K All Categories
- 103.5K Programming Languages
- 6.4K Assembler Developer
- 1.9K Basic
- 39.9K C and C++
- 2.9K C#
- 7.9K Delphi and Kylix
- 4 Haskell
- 9.6K Java
- 4.1K Pascal
- 1.3K Perl
- 2K PHP
- 533 Python
- 37 Ruby
- 4.4K VB.NET
- 1.6K VBA
- 20.8K Visual Basic
- 2.6K Game programming
- 314 Console programming
- 90 DirectX Game dev
- 1 Minecraft
- 110 Newbie Game Programmers
- 2 Oculus Rift
- 9K Applications
- 1.8K Computer Graphics
- 733 Computer Hardware
- 3.4K Database & SQL
- 535 Electronics development
- 1.6K Matlab
- 628 Sound & Music
- 257 XML Development
- 3.3K Classifieds
- 198 Co-operative Projects
- 193 For sale
- 190 FreeLance Software City
- 1.9K Jobs Available
- 602 Jobs Wanted
- 203 Wanted
- 2.9K Microsoft .NET
- 1.7K ASP.NET
- 1.1K .NET General
- 3.4K Miscellaneous
- 7 Join the Team
- 3 User Profiles
- 354 Comments on this site
- 69 Computer Emulators
- 2.1K General programming
- 187 New programming languages
- 619 Off topic board
- 182 Mobile & Wireless
- 56 Android
- 124 Palm Pilot
- 335 Multimedia
- 151 Demo programming
- 184 MP3 programming
- 0 Bash scripts
- 22 Cloud Computing
- 53 FreeBSD
- 1.7K LINUX programming
- 370 MS-DOS
- 0 Shell scripting
- 320 Windows CE & Pocket PC
- 4.1K Windows programming
- 924 Software Development
- 412 Algorithms
- 68 Object Orientation
- 89 Project Management
- 93 Quality & Testing
- 261 Security
- 7.6K WEB-Development
- 1.8K Active Server Pages
- 61 AJAX
- 2 Bootstrap Themes
- 55 CGI Development
- 28 ColdFusion
- 224 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 2.2K JavaScript
- 35 JQuery
- 296 WEB Servers
- 135 WEB-Services / SOAP

tiggerzone
Member Posts: **13**

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

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

## Comments

149:

: 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

13using 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.

607✭: 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]

13607✭:

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

13With 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?

607✭: 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

1: :

: : 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,5191. 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]