我已經寫了一個C++程序(應該是貨幣櫃檯),我在代碼中遇到了一些麻煩,我需要顯示小數。如果有問題,我使用cout
而不是printf
。小數點不在C++中的貨幣櫃檯中顯示
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main() {
// Strings and Integers
int dollars;
int pennies;
int nickles;
int quarters;
int halfDollars;
int dimes;
int fiveBill;
int tenBill;
int twentyBill;
int fiftyBill;
int hundredBill;
// Coin/Bill Amounts
int penny = 0.01;
int dollar = 1.00;
int nickle = 0.05;
int quarter = 0.25;
int halfDollar = 0.50;
int dime = 0.10;
int five = 5.00;
int ten = 10.00;
int twenty = 20.00;
int fifty = 50.00;
int hundred = 100.00;
// Enter Amount
cout << "Count your money!\n\n" << endl << "Hundred Dollar Bills: ";
cin >> hundredBill;
cout << "\nFifty Dollar Bills: ";
cin >> fiftyBill;
cout << "\nTwenty Dollar Bills: ";
cin >> twentyBill;
cout << "\nTen Dollar Bills: ";
cin >> tenBill;
cout << "\nFive Dollar Bills: ";
cin >> fiveBill;
cout << "\nOne Dollar Bills: ";
cin >> dollars;
cout << "\nHalf-Dollars: ";
cin >> halfDollars;
cout << "\nQuaters: ";
cin >> quarters;
cout << "\nDimes: ";
cin >> dimes;
cout << "\nNickles: ";
cin >> nickles;
cout << "\nPennies: ";
cin >> pennies;
// Add Together
cout << (hundred * hundredBill) + (fifty * fiftyBill) + (twenty * twentyBill) + (ten * tenBill) + (five * fiveBill) + (dollars * dollar) + (halfDollar * halfDollars) + (quarter * quarters) + (dime * dimes) + (nickle * nickles) + (penny * pennies);
system("PAUSE");
return 0;
}
整數沒有小數。 – tkausl