Answer to Question #198717 in C++ for francis

Question #198717

Write a function to calculate the rate of inflation for the past year. The function receives the current price of some item and its associated price one year ago as inputs. The item could be a kilogram of sugar or flour, for example. It then estimates the inflation rate as the difference in price divided by the year-ago price. The estimated inflation rate should be returned as a value of type double giving the rate in percent, for example, 5.3, if the inflation was estimated to be 5.3 percent. 


1
Expert's answer
2021-05-25T23:10:19-0400
#include<iostream>
#include<cmath>
using namespace std;
double inflationMethod(double previousCost,double currentCost)
{  
    return ((currentCost - previousCost)/currentCost);
}
int main()
{
   double previousCost,currentCost,rate;
   char option;
   do {
       cout<<"Enter previous year cost of the item: ";
       cin>>previousCost;
       cout<<"Enter present year cost of the item: ";
       cin>>currentCost;
       rate = inflationMethod(previousCost,currentCost);
       cout<<"Rate of inflation:"<<rate*100<<"%"<<endl;
       cout<<"To continue then enter 'Y': ";
       cin>>option;
   } while (option=='Y' || option=='y');
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog