Chapter 3 – #11: 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>
#include <iomanip>
using namespace std;

int main()
{
    // Constant
    const int TWELVE_MONTHS = 12;

    // Variables
    float loan_payment,
          insurance,
          gas,
          oil,
          tires,
          maintenance,
          total_monthly_exp,
          annual_cost;
    /**
     * 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.
     */
    cout << "\nEnter the following monthly costs for your";
    cout << "\nautomobile: " << endl;
    cout << "Loan Payment : $";
    cin >> loan_payment;
    cout << "Insurance    : $";
    cin >> insurance;
    cout << "Gas          : $";
    cin >> gas;
    cout << "Oil          : $";
    cin >> oil;
    cout << "Tires        : $";
    cin >> tires;
    cout << "Maintenae    : $";
    cin >> maintenance;
    cout << endl;


    // Calculate total monthly cost of these expenses
    total_monthly_exp = loan_payment + insurance + gas + oil + tires + maintenance;

    // Calculate total annual cost of these expenses
    annual_cost = total_monthly_exp  * TWELVE_MONTHS;

    // display the total monthly cost of these expenses
    cout << "\nMonthly car expenses = $" << total_monthly_exp;

    // display the total annual cost of these expenses
    cout << "\nTotal annual cost = $" << annual_cost;
    cout << endl;

    return 0;
}

>_Get The Book!

>_ Video Walk Through

This video includes a step by step process of how I solve programming challenge #11.

>_ Chapter 3 Programming Playlist

>_That’s it!

Thank you for taking interest in what I do! I hope it was helpful for you as much as it helped me along my journey in learning to code!

>_Chapter 3 Posts:

Starting Out With C++ | Chapter 3 | Programming Challenge Solutions

Leave a Reply