Please take a look at the below code
#include <QtCore/QCoreApplication>
#include <iostream>
int main(int argc, char *argv[])
{
using namespace std;
double purchaseAmount;
double paidAmount;
float balance;
int change, quarters, dimes, nickels, pennies, tenDollar, fiveDollar; // declare variables
cout << "Enter Total purchased amount" << endl;
cin >> purchaseAmount;
cout << "Enter Total paid amount" << endl;
cin >> paidAmount;
balance = paidAmount - purchaseAmount ;
tenDollar = balance / 10; // calculate the number of Ten Dollars
change = tenDollar % 10 ; // calculate the change needed
change = balance * 100;
quarters = change / 25; // calculate the number of quarters
change = change % 25; // calculate remaining change needed
dimes = change / 10; // calculate the number of dimes
change = change % 10; // calculate remaining change needed
nickels = change / 5; // calculate the number of nickels
pennies = change % 5; // calculate pennies
cout << "\nQuarters: " << quarters << endl; // display # of quarters
cout << " Dimes: " << dimes << endl; // display # of dimes
cout << " Nickels: " << nickels << endl; // display # of nickels
cout <<" Pennies: " << pennies << endl; // display # of pennies
cout <<" Ten dollar: " << tenDollar << endl; // display # of Ten dollar
//cout <<" Five dollar: " << fiveDollar << endl; // display # of Ten dollar
return (0);
}
What I am trying to do here, calculate the change left in ten dollars,quarters, dimes, nickels and pennies. And for example when I run the program this way -
Enter Total purchased amount
9.75
Enter Total paid amount
20
Quarters: 4
Dimes: 0
Nickels: 0
Pennies: 0
Ten dollar: 1
Which is wrong. That being said, the above output is wrong. Rather it should be
Enter Total purchased amount
9.75
Enter Total paid amount
20
Quarters: 1
Dimes: 0
Nickels: 0
Pennies: 0
Ten dollar: 1
So what am I doing wrong here?
Thanks