Write a C++ program that asks the user to enter the monthly costs for the follow
ID: 3589962 • Letter: W
Question
Write a C++ program that asks the user to enter the monthly costs for the following expenses incurred from operating your automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost of these expenses, and a projected total annual cost of these expenses. Label each cost. The labels should be left aligned and have a column width of 30 characters. The cost should be aligned right and displayed with two decimal places with a column width of 15. If the yearly total is greater than 1000 dollars, add 10 percent of the yearly total to the yearly total.
Explanation / Answer
#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 << ((12 * (loan_Payment + insurance + gas + oil + tires + maintenance))*.10)
+ (12 * (loan_Payment + insurance + gas + oil + tires + maintenance))
<< right << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.