This question has been answered
Question

This is a code for my computer science class.I keep receiving compiling errors.

//This program calculates the inflation rate given two Consumer Price Index values and prints it to the monitor.


#include <iostream>

using namespace std;


/*

 * InflationRate - calculates the inflation rate given the old and new consumer price index

 * @param old_cpi: is the consumer price index that it was a year ago

 * @p..;@returns the computed inflation rate or 0 if inputs are invalid.

 */

double InflationRate(float old_cpi, float new_cpi);

float iRate,avg,total;

int count;

char ans;

int main()   //C++ programs start by executing the function main

{

   // TODO #1: declare two float variables for the old consumer price index (cpi) and the new cpi

   float old_cpi, new_cpi;


   // TODO #2: Read in two float values for the cpi and store them in the variable

   cout<<"Enter the old and new consumer price indices: ";

   cin>>old_cpi>>new_cpi;


   // TODO #3: call the function InflationRate with the two cpis

   iRate=InflationRate(old_cpi,new_cpi);


   // TODO #4: print the results

   cout<<"Inflation rate is"<<iRate<<endl;



   // BONUS #1: Put the logic in TODO #2-4 in a loop that asks the user to enter 'y' if there's more data

   cout<< "Try again?(y or Y):";

   cin>>ans;

   do

   {

       float old_cpi, new_cpi;

       cout<<"Enter the old and new consumer price indices: ";

       cin>> old_cpi>>new_cpi;

       cout<< "Try again? y or Y"<<endl;

       cin>>ans;

   }

   while (ans=='y'||ans=='Y');

   count++;

   return 0;

   

}

   


   // BONUS #2: Keep a running total of the valid inflation rates and the number of computed rates to calculate the average rate.

   // Print the results after the loop

   avg=total/count;

   cout<<"Average rate is "<<avg;



// double InflationRate(float old_cpi, float new_cpi)

// precondition:   both prices must be greater than 0.0

// postcondition:  the inflation rate is returned or 0 for invalid inputs

double InflationRate(float old_cpi, float new_cpi)

{

   // TODO: Implement InflationRate to calculate the percentage increase or decrease

   // Use (new_cpi - old_cpi) / old_cpi * 100

   if(old_cpi<0||new_cpi<0)

   {

      return 0;

   }

   else

   {

      total=(new_cpi-old_cpi)/old_cpi*100);

      return total;

   }

   

Answered by Expert Tutors
Step-by-step explanation
The student who asked this found it Helpful
Overall rating 100%
This is a code for my computer science class. I keep receiving compiling errors....
Get unstuck

204,222 students got unstuck by Course
Hero in the last week

step by step solutions

Our Expert Tutors provide step by step solutions to help you excel in your courses