Question

In: Computer Science

Write a C++ program that asks the user to enter the monthly costs for the following...

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

Solutions

Expert Solution

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;
}


Related Solutions

Write a program that asks the user to enter the monthly costs for the following expenses...
Write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: Loan payment Insurance Gas Oil Tires Maintenance Write a function that takes these six items as arguments and computes the total cost of these expenses. Write a main program that asks the user for these six items and calls your function. Print total monthly cost and the total annual cost for these expenses.
Write a program that asks the user to enter the monthly costs for the following expenses...
Write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. Using the following test data: 310.34 104.95 78.34 12.34 8.12 45.00 Your output should look like this: Enter the monthly loan payment amount: Enter the monthly cost of insurance:...
In Python write a program that asks the user to enter the monthly costs for the...
In Python write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
Q2. Design a Pearson modular program that asks the user to enter the monthly costs for...
Q2. Design a Pearson modular program that asks the user to enter the monthly costs for each of the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, and maintenance (create a module for each expense). The program should then display the total monthly cost of these expenses, and the total annual cost of these expenses in the main Module. Use Pass arguments By Reference method to design your modules. Submit your pseudocode with comments at...
Write a C program that loops and asks a user to enter a an alphanumeric phone...
Write a C program that loops and asks a user to enter a an alphanumeric phone number and converts it to a numeric one. No +1 at the beginning. You can put all code in one quiz1.c file or put all functions except main in phone.c and phone.h and include it in quiz1.c Submit your *.c and .h files or zipped project */ #pragma warning (disable: 4996) //windows #include <stdio.h> #include <string.h> #include <stdbool.h> #include <ctype.h> enum { MaxLine =...
C++ write a program that asks the user to enter the hours and rate then calculate...
C++ write a program that asks the user to enter the hours and rate then calculate the gross pay for an employee, the program should test if the hours are regular (40), any hour more than 40 should be paid with the overtime rate: 1.5*rate. The program should ask repeatedly the user if he/she wants to continue: y or n, if the user types y, then the program should ask for the hours and rate for another employee then display...
write a program in c++ that asks the user to enter their 5 test scores and...
write a program in c++ that asks the user to enter their 5 test scores and calculates the most appropriate mean. Have the results print to a text file and expected results to print to screen.
In the space provided below write a C++ program that asks the user to enter their...
In the space provided below write a C++ program that asks the user to enter their quarterly earnings for the past two years stores the data in a 2-dimensional array. The program then computes both the annual earnings as well as the total earning and prints the results along with the 2-dimensional array on screen as well as onto a file.
Write a C program that performs the following: Asks the user to enter his full name...
Write a C program that performs the following: Asks the user to enter his full name as one entry. Asks the user to enter his older brothers’ names each at a time (the user should be instructed by the program to enter NULL if he does not have any older brother). Asks the user to enter his younger brothers’ names each at a time (the user should be instructed by the program to enter NULL if he does not have...
in C++, Write a program that asks the user to enter 6 numbers. Use an array...
in C++, Write a program that asks the user to enter 6 numbers. Use an array to store these numbers. Your program should then count the number of odd numbers, the number of even numbers, the negative, and positive numbers. At the end, your program should display all of these counts. Remember that 0 is neither negative or positive, so if a zero is entered it should not be counted as positive or negative. However, 0 is an even number....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT