In: Computer Science
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.
Sample Output:
Loan Payment $ 303.28
Insurance 75.00
Gas 125.00
Oil 45.00
Tires 0.00
Maintenance 15.00
Total $ 563.28
Yearly Total $ 6759.36
10% $ 675.93
Grand Total $ 7435.29
input code:
output:
code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
/*declare the variables*/
double Loan_P,Insurance,Gas,Oil,Tires,Maintenance,Tax=0;
/*take input from user*/
cout<<"Loan Payment :$ ";cin>>Loan_P;
cout<<"Insurance:$ ";cin>>Insurance;
cout<<"Gas:$ ";cin>>Gas;
cout<<"Oil:$ ";cin>>Oil;
cout<<"Tires:$ ";cin>>Tires;
cout<<"Maintenance:$ ";cin>>Maintenance;
/*display the input*/
cout<<setw(30)<<"-----------Entered Data
is-----------"<<endl;
cout<<setw(30)<<"Loan Payment
"<<setw(15)<<setprecision(2)<<fixed
<<Loan_P<<endl;
cout<<setw(30)<<"Insurance
"<<setw(15)<<setprecision(2)<<Insurance<<endl;;
cout<<setw(30)<<"Gas
"<<setw(15)<<setprecision(2)<<Gas<<endl;;
cout<<setw(30)<<"Oil
"<<setw(15)<<setprecision(2)<<Oil<<endl;;
cout<<setw(30)<<"Tires
"<<setw(15)<<setprecision(2)<<Tires<<endl;;
cout<<setw(30)<<"Maintenance
"<<setw(15)<<setprecision(2)<<Maintenance<<endl;;
/*calculate the sum and print monthly and yearly Total*/
double sum=Loan_P+Insurance+Gas+Oil+Tires+Maintenance;
cout<<setw(30)<<"Total
"<<setw(15)<<setprecision(2)<<sum<<endl;
cout<<setw(30)<<"Yearly Total
"<<setw(15)<<setprecision(2)<<12*sum<<endl;
/*if Yearly Total >1000 than print the Tax*/
if(12*sum>1000)
{
Tax=12*sum*0.1;
cout<<setw(30)<<"10%
"<<setw(15)<<setprecision(2)<<Tax<<endl;
}
/*print the Grand Total*/
cout<<setw(30)<<"Grand Total
"<<setw(15)<<setprecision(2)<<12*sum+Tax<<endl;
return 0;
}