Programming Challenge Chapter 3 – Q #9 Automobile Costs – Tony Gaddis – Starting Out With C++

Programming Challenge Chapter 3 – Q #9 Automobile Costs – Tony Gaddis – Starting Out With C++



Problem: -

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.

Solution: -

#include <iostream>

using namespace std;

int main()

{

      int loan, gas, oil, insurance, tires, maintainance;

      int annual_expendature = 0, monthly_expendature = 0;

 

      cout << "This Program Calculate AutoMobile Cost, Enter Required Data\n";

      cout << "Enter Loan Ammount:      $";

      cin >> loan;

      cout << "Enter Insurance Ammount: $";

      cin >> insurance;

      cout << "Enter Tires Cost:        $";

      cin >> tires;

      cout << "Enter Oil Cost:          $";

      cin >> oil;

      cout << "Enter Gas Cost:          $";

      cin >> gas;

      cout << "Enter Maintainance Cost: $";

      cin >> maintainance;

     

      monthly_expendature = loan + insurance + tires + oil + gas + maintainance;

      annual_expendature = monthly_expendature * 12;

 

      cout << "\nMonthly Automobile Cost is " << monthly_expendature << endl;

      cout << "Annual Automobile Cost is  " << annual_expendature;

      return 0;

}

This is the solution of this question




OUTPUT OF THIS QUESTION 

Input is highlighted with yellow color.


Explanation of this Solution

  1. Declare six int variables for input.
  2. Declare two int variable for calculation.
  3. Take input one by one from the user by using cin.
  4. Calculate the value of cost.
  5.  In last, display output on the screen.
  6. Return 0 to the main function.

Also, I attach CPP file of this problem. You can download this file

Click Here to Download This File




Thanks! 



Post a Comment

0 Comments