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.

Respuesta :

Answer:

#include

using namespace std;

void getInput(double currentPrice, double priceYear1, double priceYear2){

   cin >> currentPrice;

   cin >> priceYear1;

   cin >> priceYear2;

}

void printInflationRate( double myRate){

   cout<< "The inflation rate for the year price = "<< rate;

}

void calInflation(double targetPrice, double yearBefore){

   double rate = (yearBefore - targetPrice)/ yearBefore;

   printInflationRate( rate);

}

int main(){

   double cprice, year1price, year2price, rate;

   getInput(cprice, year1price, year2price);

   calInflationRate(cprice, year1price);

   calInflationRate(year1price, year2price);

   return 0;

}

Explanation:

The C++ program source code defines three void functions (functions with no return statement), 'calInflationRate', 'getInput', and printInflationRate. In the main program code, the four float point number variables are declared, and the getInput function assigns values to them. The calInflationRate function calculates the inflation rate of a given year, and it in, the printInflationRate is called to print the output on the screen.

The inflation calculator program is an illustration of Python functions; where the functions are executed when called or evoked

The inflation program

The inflation calculator program written in Python, where comments are used to explain each action is as follows:

#Thie function gets all input

def getInput():

   cPrice = float(input("Current Price: "))

   pYear1 = float(input("Year 1 Price: "))

   pYear2 = float(input("Year 2 Price: "))

   return cPrice, pYear1, pYear2

#This function prints inflation rate

def printinfRate(myinfRate):

  print("Inflation infRate: ",myinfRate)

#This function calculates inflation rate

def calcinfRate(cPrice, pPrice):

  infinfRate = (pPrice - cPrice)/ pPrice

  printinfRate(round(infinfRate,2))

#The main function begins here

#This gets the prices

cprice, pYear1, pYear2 =  getInput()

#The next 2 lines calls the calcinfRate function to calculate the inflation rate

calcinfRate(cprice, pYear1);

calcinfRate(pYear1, pYear2)

Read more about Python Programs at:

https://brainly.com/question/16397886