Chapter 3 – #10: How Much Insurance? – Tony Gaddis – Starting Out With C++

>_ Problem

Many financial experts advise that property owners should insure their homes or buildings for at least 80 percent of the amount it would cost to replace the structure. Write a program that asks the user to enter the replacement cost of a building and then displays the minimum amount of insurance he or she should buy for the property.

>_ Solution

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    // Constane variables
    const float INSURE_PERCENTAGE = .80;

    float replacement_cost,
          min_amount_insurance;

    // Explain the program
    cout << endl;
    cout << "------------------------------------" << endl;
    cout << "Many financial experts advise that "  << endl;
    cout << "property owners should insure their " << endl;
    cout << "homes or buildings for at least 80 "  << endl;
    cout << "percent of the amount it would cost " << endl;
    cout << " to replace the structure."           << endl;
    cout << "------------------------------------\n\n";
    cout << "Press \"Enter\" to continute.\n"      << endl;
    cin.get();

    cout << "This program will calculate the 80 "  << endl;
    cout << "percent for you. " << endl;
    cout << "------------------------------------\n\n";
    cout << "Enter the replacement cost of your "  << endl;
    cout << "home or building     : $";
    cin >> replacement_cost;

    // Calculate Min amount for insurance
    min_amount_insurance = replacement_cost * INSURE_PERCENTAGE;

    // Display min amount to buy for property
    cout << setprecision(2) << fixed;

    cout << "The minimum amount of insurance " << endl;
    cout << "to buy at %80 is        : $";
    cout << min_amount_insurance << endl;
    cout << endl;

    return 0;
}

>_Get The Book!

>_ Video Walk Through

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

>_ Chapter 3 Programming Challenges 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!

>_ All Chapter 3 Posts:

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

Leave a Reply