C Write a program that outputs inflation rates for two succe

C++

Write a program that outputs inflation rates for two successive years and whether the inflation is increasing or decreasing. Ask the user to input the current price of an item and its price one year and two years ago. To calculate the inflation rate for a year, subtract the price of the item for that year from the price of the item one year ago and then divide the result by the price a year ago. Your program must contain at least the following functions: a function to get the input, a function to calculate the results, and a function to output the results. Use appropriate parameters to pass the information in and out of the function. Do not use any global variables.

Solution

#include <iostream>

using namespace std;

void getinp(double* pc, double* p1, double* p2);

void inflationRate(double pc, double p1, double p2, double* rate1, double* rate2);

void showresult(double rate1, double rate2);

#include <iostream>

using namespace std;

void getinp(double* pc, double* p1, double* p2);

void inflationRate(double pc, double p1, double p2, double* rate1, double* rate2);

void showresult(double rate1, double rate2);

int main ()

{

double pc = 0, p1 = 0, p2 = 0, ra1 = 0, ra2 = 0;

getinp(&pc, &p1, &p2);inflationRate(pc, p1, p2, &ra1, &ra2);

showresult(ra1, ra2);

cin.clear();

cin.ignore(255, \'\ \');

cin.get();

return 0;

}

void getinp( double* pc, double* p1, double* p2)

{

cout << \" please enter the current price\" <<endl;

cin >> *pc;

cout << \" please enter the the price a year ago\" <<endl;

cin >> *p1;

cout << \" please enter the price two years ago\" <<endl;

cin >> *p2;

}

void inflationRate(double pc, double p1, double p2, double* rate1, double* rate2)

{

*rate1 = ( p1-p2)/p2;

*rate2 = ( pc-p1)/p1;

}

void showresult(double rate1, double rate2)

{

if (rate1 < rate2)

cout << \"The inflation rate is increasing\" << endl;

    else if (rate1 > rate2)

   cout << \"The inflation rate is decreasing\" << endl;

    else

    cout << \"There is no change in the inflation rate\" << endl;

    cout << \"The rate for last year:\" << rate1 << endl;

    cout << \"The rate for this year:\" << rate2 << endl;

}

C++ Write a program that outputs inflation rates for two successive years and whether the inflation is increasing or decreasing. Ask the user to input the curre
C++ Write a program that outputs inflation rates for two successive years and whether the inflation is increasing or decreasing. Ask the user to input the curre

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site