Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that deals with inflation, which is essentially the rising cost

ID: 3668257 • Letter: W

Question

Write a program that deals with inflation, which is essentially the rising cost of general goods over time. That is, the price of goods, such as a packet of peanuts, goes up as time goes by. So, you will write a program to gauge the expected cost of an item in a specified number of years. The program asks for the cost of the item, the number ol years, and the rate of inflation. The output is the estimated cost of the item after that number of years, using the given inflation rate. The user enters the inflation rate as a percentage, for example 4.5. You will have to convert the percentage to a fraction (like 0.045), and then use a loop to estimate the item's price adjusted for inflation. Note that you must check each of the values provided by the user to make sure that they are reasonable. To actually adjust the price for inflation, you need to increase the price by the inflation rate each year separately. For example, if you have an item that is initially priced at $10, with an inflation rate of 10%, then the adjusted prices will be: In other words, to calculate the price after another year, you have to use the value from the current year. NOT the original price. To do this, you have to use a while or for loop.

Explanation / Answer

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/


#include <iostream>

using namespace std;

float postYearPrice(float cPrice, float iRate) {
    float nPrice = iRate * cPrice;
  
    return nPrice;
}

float inflationRate(float cPrice, float oPrice) {
    float rate = ((cPrice - oPrice)/ oPrice)* 10;
  
    return rate;
}

int main(int argc, char** argv) {

    float iPrice;   // Price of the item
    float oPrice;   // Price of the item a year ago
    float iRate;    // Inflation Rate
    float nPrice;   // new price after inflation applied
    char isDone;    // User chooses if they would like to run program again
  
    do {
      
        cout<< "Choose the current price of an item: "<<endl;
        cin>>iPrice;
  
        cout<< "Choose the price of that same item a year ago: "<< endl;
        cin>> oPrice;
      
        iRate = inflationRate(iPrice, oPrice);
      
        cout<< "The rate of inflation for this product is: "<<iRate << "%"<< endl;
      
        nPrice = postYearPrice(iPrice, iRate);
      
        cout<< "The cost of this product in the next year is: $"<<nPrice<<endl;
      
        nPrice = postYearPrice(nPrice, iRate);
      
        cout<< "The cost of this product in two years is: $"<< nPrice<<endl;
      
        cout<< "Would you like to check another item?"<<endl;
        cout<< "Yes: Y       No: N"<< endl;
        cin>>isDone;
      
    } while(isDone == 'Y' || isDone == 'y');
  
    return 0;
}

output

                                                                                                                                                 
Choose the current price of an item:                                                                                                                        
500                                                                                                                                                         
Choose the price of that same item a year ago:                                                                                                              
10                                                                                                                                                          
The rate of inflation for this product is: 490%                                                                                                             
The cost of this product in the next year is: $245000                                                                                                       
The cost of this product in two years is: $1.2005e+08                                                                                                      
Would you like to check another item?                                                                                                                       
Yes: Y       No: N                                                                                                                                          
n                                                                                                                                                           

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote