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

Write a program to gauge the rate of inflation for the past year. The program as

ID: 3540407 • Letter: W

Question

Write a program to gauge the rate of inflation for the past year. The program ask for the price of an item(Such as a hot dog or a one carat diamond) both one year ago and today. It estimates the inflation rate as the difference in price divided by the year ago price. Your program should allow the user to repeat this calculation as often as the user wishes. Define a function to compute the rate of inflation. The inflation should be a value of type double giving the rate as a percent,
for example 5.3 for 5.3%.

Enhance your program from the previous programming project by having it also print out the estimated price of the item in one and in two years from the time of the calculation. The increase in cost over one year is estimated as the inflation rate times the price at the start of the year. Define a second function to determine the estimated cost of an item in one year, given the current price of the item and the inflation rate as arguments.

Explanation / Answer

#include<iostream>
using namespace std;
double price_latest(double inflation,double price_now)
{
return inflation*price_now;
}
int main()
{
double price_ago;
double price_now;
cout << "price of an item(Such as a hot dog or a one carat diamond) one year ago and now";
cin >> price_ago >> price_now;
cout << endl;
double inflation = (price_now - price_ago)/(price_ago);
cout << "inflation is " << inflation << "%" << endl;
double price_after_one_year = price_now + price_latest(inflation,price_now);
cout << "price in next year is " << price_after_one_year << endl;
double price_after_two_year = price_after_one_year + price_latest(inflation,price_after_one_year);
cout << "price after two years is " << price_after_two_year << endl;

return 0;
}

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