|
 |
|
 |
02-09-2007, 12:22 PM
|
#1 (permalink)
|
|
Recruit
Join Date: Feb 2007
Posts: 18
|
Another coding problem
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:
Code:
#include <iostream>
//#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
Last edited by redhead; 02-09-2007 at 01:38 PM.
Reason: Added [code][/code] tags
|
|
|
02-09-2007, 01:41 PM
|
#2 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,694
|
Here is your problem:
Code:
int DOLLARS = 0.0;
int QUARTERS = 0.0;
int DIMES = 0.0;
int NICKELS = 0.0;
int PENNIES = 0.0;
...
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) ;
...
cout << "dollars: " << Dollars << endl;
cout << "quarters: " << Quarters << endl;
cout << "dimes: " << Dimes << endl;
cout << "nickels: " << Nickels << endl;
cout << "pennies: " <<Pennies<< endl;
...
First off, you're tryig to store decimal numbers into a type INT, remember for that to be accomplished the container must be of type FLOAT.
Second, when you output the result, you address totaly different variables, remember, the programming language is case sensitive.
|
|
|
02-09-2007, 02:01 PM
|
#3 (permalink)
|
|
Recruit
Join Date: Feb 2007
Posts: 18
|
thanks for the input but getting negative numbers when I input data where am I going wrong?
|
|
|
02-09-2007, 02:23 PM
|
#4 (permalink)
|
|
Recruit
Join Date: Feb 2007
Posts: 18
|
after making the changes:
#include <iostream>
using std:: cout;
using std:: cin;
using std:: endl;
int main()
{
//declare variables
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 amount
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 change amount
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
}
these are the errors I 'm being given:
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(24): error C2065: 'amountDue' : undeclared identifier
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(26): error C2065: 'amountPaid' : undeclared identifier
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(32): error C2065: 'dimes' : undeclared identifier
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(39): error C2065: 'Dimes' : undeclared identifier
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(37): error C2065: 'Dollars' : undeclared identifier
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(33): error C2065: 'nickels' : undeclared identifier
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(40): error C2065: 'Nickels' : undeclared identifier
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(41): error C2065: 'Pennies' : undeclared identifier
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(31): error C2065: 'quarters' : undeclared identifier
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(38): error C2065: 'Quarters' : undeclared identifier
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(39): error C2593: 'operator <<' is ambiguous
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(434): could be 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits>::_Mysb *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(414): or 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(38): error C2593: 'operator <<' is ambiguous
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(434): could be 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits>::_Mysb *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(414): or 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(41): error C2593: 'operator <<' is ambiguous
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(434): could be 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits>::_Mysb *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(414): or 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(394): or 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(long double)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(37): error C2593: 'operator <<' is ambiguous
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(434): could be 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits>::_Mysb *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(414): or 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(394): or 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(long double)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(374): or 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(double)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(354): or 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(float)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(333): or 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(313): or 'std::bas
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(40): error C2593: 'operator <<' is ambiguous
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(434): could be 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits>::_Mysb *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(414): or 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(394): or 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(long double)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(374): or 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(double)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(354): or 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(float)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(333): or 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(313): or 'std::bas
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(24): error C2593: 'operator >>' is ambiguous
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\istream(413): could be 'std::basic_istream<_Elem,_Traits>::_Myt &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_istream<_Elem,_Traits>::_Mysb *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\istream(394): or 'std::basic_istream<_Elem,_Traits>::_Myt &std::basic_istream<_Elem,_Traits>::operator >>(void *& )'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\istream(376): or 'std::basic_istream<_Elem,_Traits>::_Myt &std::basic_istream<_Elem,_Traits>::operator >>(long double &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\istream(358): or 'std::basic_istream<_Elem,_Traits>::_Myt &std::basic_istream<_Elem,_Traits>::operator >>(double &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(26): error C2593: 'operator >>' is ambiguous
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\istream(413): could be 'std::basic_istream<_Elem,_Traits>::_Myt &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_istream<_Elem,_Traits>::_Mysb *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\istream(394): or 'std::basic_istream<_Elem,_Traits>::_Myt &std::basic_istream<_Elem,_Traits>::operator >>(void *& )'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\istream(376): or 'std::basic_istream<_Elem,_Traits>::_Myt &std::basic_istream<_Elem,_Traits>::operator >>(long double &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\istream(358): or 'std::basic_istream<_Elem,_Traits>::_Myt &std::basic_istream<_Elem,_Traits>::operator >>(double &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\istream(339): or 'std::basic_istream<_Elem,_Traits>::_Myt &std::basic_istream<_Elem,_Traits>::operator >>(float &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\istream(320): or 'std::basic_istream<_Elem,_Traits>::_Myt &std::basic_istream<_Elem,_Traits>::operator >>(unsigned __int64 &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\istream(301): or 'std:
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(33): error C3861: 'changeAmount': identifier not found, even with argument-dependent lookup
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(32): error C3861: 'changeAmount': identifier not found, even with argument-dependent lookup
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(33): error C3861: 'dimes': identifier not found, even with argument-dependent lookup
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(33): error C3861: 'dimes': identifier not found, even with argument-dependent lookup
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(33): error C3861: 'dollars': identifier not found, even with argument-dependent lookup
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(31): error C3861: 'dollars': identifier not found, even with argument-dependent lookup
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(32): error C3861: 'quarters': identifier not found, even with argument-dependent lookup
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(17): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(18): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(20): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(19): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(16): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(19): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
These are the errors when I run the program how do I correct these errors I'm new to all this and I really can use the help.
|
|
|
02-10-2007, 02:11 AM
|
#5 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,694
|
Nothing has changed in your code, from my previus observation, your declaring the DOLLARS/NICKELS/etc as int, when you try to assign a value of 0.0 and later on somevalue divided with some value, this is a floating point arritmetic, which values only can be stored in a container of type float ie: This is why you're getting the:
Quote:
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(17): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(18): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
|
Errors
Then you read from std::cin into a variabel amountDue/ amountPaid these are never declared, the program dosn't know what they are, this is why the errors:
Quote:
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(24): error C2065: 'amountDue' : undeclared identifier
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(26): error C2065: 'amountPaid' : undeclared identifier
|
Appear.
Next thing, when you're displaying the values, you refere to variabels named Dollars/ Nickels/etc these are again variabels which are unknown in your program, since the programming language is case sensitive, which means a variabel named DOLLARS is something entirely different than one named Dollars or one named doLLars or how ever you plan on mengling the capital letters in the name.
This is why you're getting teh
Quote:
c:\Course Technology\21711-1\Cpp\Chap04\Ch4AppE10 Solution\Ch4AppE10 Project\Ch4AppE10.cpp(39): error C2593: 'operator <<' is ambiguous
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(434): could be 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits>::_Mysb *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(414): or 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
|
Errors.
Fix these simple things, and you'll see a whole different run of the program.
|
|
|
09-26-2007, 06:55 AM
|
#6 (permalink)
|
|
Recruit
Join Date: Sep 2007
Posts: 2
|
this should help
I just had to do this problem in my Intro to C++ class and here's how I wrote it. You can see from the test output at the bottom that it works correctly.
//Ch4AppE10.cpp - calculates and displays the amount of change due a customer
//Created by Nathanael Lowery on September 24, 2007
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
//declare variables
double amountDue = 0.0;
double amountPaid = 0.0;
double change = 0.0;
double remainder = 0.0;
double dollars = 0.0;
double quarters = 0.0;
double dimes = 0.0;
double nickels = 0.0;
double pennies = 0.0;
//get input items from user
cout << "Enter the amount due: ";
cin >> amountDue;
cout << "Enter the amount paid: ";
cin >> amountPaid;
//calculate change due
change = amountPaid - amountDue;
dollars = int(change);
remainder = change - dollars;
quarters = int(remainder / .25);
remainder = remainder - quarters * .25;
dimes = int(remainder / .1);
remainder = remainder - dimes * .1;
nickels = int(remainder / .05);
remainder = remainder - nickels * .05;
pennies = remainder / .01;
//display output items
cout << "The change due is $" << change << "." << endl;
cout << "That's " << dollars << " dollars, " << quarters << " quarters, " << dimes << " dimes, " << nickels
<< " nickels, and " << pennies << " pennies." << endl;
return 0;
} //end of main function
//Test Output 1
/*Enter the amount due: 75.34
Enter the amount paid: 80.00
The change due is $4.66.
That's 4 dollars, 2 quarters, 1 dimes, 1 nickels, and 1 pennies.
Press any key to continue*/
//Test Output 2
/*Enter the amount due: 39.67
Enter the amount paid: 50.00
The change due is $10.33.
That's 10 dollars, 1 quarters, 0 dimes, 1 nickels, and 3 pennies.
Press any key to continue*/
//Test Output 3
/*Enter the amount due: 45.55
Enter the amount paid: 45.55
The change due is $0.
That's 0 dollars, 0 quarters, 0 dimes, 0 nickels, and 0 pennies.
Press any key to continue*/
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 11:53 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|