-1
#include <iostream>
#include <string>
using namespace std;
int main() {
double loan_Payment;
double insurance;
double gas;
double oil;
double tires;
double maintenance;
/// text setup
std::cout.width(30); std::cout << std::left << "Loan Payment";
std::cout.width(15); std::cin >> std::right >> loan_Payment;
std::cout.width(30); std::cout << std::left << "Insurance";
std::cout.width(15); std::cin >> std::right >> insurance;
std::cout.width(30); std::cout << std::left << "Gas";
std::cout.width(15); std::cin >> std::right >> gas;
std::cout.width(30); std::cout << std::left << "Oil";
std::cout.width(15); std::cin >> std::right >> oil;
std::cout.width(30); std::cout << std::left << "Tires";
std::cout.width(15); std::cin >> std::right >> tires;
std::cout.width(30); std::cout << std::left << "Maintenance" ;
std::cout.width(15); std::cin >> std::right >> maintenance;
// adding total.yearly total, 10%
std::cout.width(30); std::cout << std::left << "Total";
std::cout.width(15); std::cout << (loan_Payment + insurance + gas + oil + tires + maintenance) << right << endl;
std::cout.width(30); std::cout << std::left << "Yearly Total";
std::cout.width(15); std::cout << (12 * (loan_Payment + insurance + gas + oil + tires + maintenance)) << right << endl;
std::cout.width(30); std::cout << std::left << "10%";
std::cout.width(15); std::cout << (12 * (loan_Payment + insurance + gas + oil + tires + maintenance))*.10 << right << endl;
//if yearly total is greater than 1000 add 10 percent of the yearly total
double yearly_total;
yearly_total = (12 * (loan_Payment + insurance + gas + oil + tires + maintenance));
if (yearly_total >= 1000)
std::cout.width(30); std::cout << "Grand Total" << left;
std::cout.width(60); std::cout << ((12 * (loan_Payment + insurance + gas + oil + tires + maintenance))*.10) + (12 * (loan_Payment + insurance + gas + oil + tires + maintenance)) << right << endl;
}
寫C++程序,要求用戶輸入的每月費用從操作您的汽車發生的下列費用:貸款支付,保險,氣,油,輪胎和維護。然後,程序應顯示這些費用的每月總費用以及這些費用的預計年度總費用。我的「總計」輸出不會停留右對齊與其他輸出
標出每個成本。標籤應該左對齊,列寬爲30個字符。成本應正確對齊,並以小數點後兩位顯示,列寬爲15.
如果年總數大於1000美元,則將年總數的10%添加到年總數中。
你想用'std :: cin >> std :: right >> loan_Payment來做什麼?''? – NathanOliver
還有一些額外的'std :: cout.width(15)',因爲在使用'std :: cout'之前再次改變了寬度,所以不會做任何事情。 – chris
問題左對齊然後cin輸入答案正確對齊。 –