請看看下面的代碼計算美元就在貨幣改革計劃 - C++
#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);
}
我想在這裏做,計算剩下十塊錢,宿舍,硬幣,鎳的變化和便士。例如,當我用這種方式運行程序 -
Enter Total purchased amount
9.75
Enter Total paid amount
20
Quarters: 4
Dimes: 0
Nickels: 0
Pennies: 0
Ten dollar: 1
這是錯誤的。這就是說,上面的輸出是錯誤的。相反它應該是
Enter Total purchased amount
9.75
Enter Total paid amount
20
Quarters: 1
Dimes: 0
Nickels: 0
Pennies: 0
Ten dollar: 1
那麼我在這裏做錯了什麼?
感謝
那麼我在這裏做錯了什麼? - 期待別人做你的功課我猜... – dtech
不,我不是..我自己開始,尋求幫助。 – user15169
我們似乎已經丟失了下面的代碼... –