How do i get my output to look like the expect output sample

Write your question here.
My concern is the do-while loop.
My output is:
Enter the old and new consumer price indices Inflation rate is -0.0390204
Enter the old and new consumer price indices:Try again? y or Y

However, the expect output for my lab is

Enter the old and new consumer price indices: Inflation rate is -0.0390204
Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.167049
Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.0752572
Try again? (y or Y): Average rate is -0.0436042

Please help and be as specific as possible. Thank you
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  //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
 * @param new_cpi: is the consumer price index that it is currently 
 * @returns the computed inflation rate or 0 if inputs are invalid.
 */
 double InflationRate(float old_cpi, float new_cpi);
 

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;
    cout << "Enter the old and new consumer price indices ";

   // TODO #2: Read in two float values for the cpi and store them in the variables
    cin >> old_cpi >> new_cpi;

   // TODO #3: call the function InflationRate with the two cpis
   //call the function and add a variable and assign it.
    double Rate = InflationRate(old_cpi, new_cpi);
    
   // TODO #4: print the results
   cout << "Inflation rate is " << Rate << endl;
   
   //Part 2 add a loop 
  char userInput;
  do  
  {
 
  float old_cpi, new_cpi;
  cout << "Enter the old and new consumer price indices: ";
  cin >> old_cpi >> new_cpi << endl;
  cout << "Try again? y or Y" << endl;
  cin >> userInput; 
  
  } 
  while (userInput == 'y' || userInput == 'Y');  
  
 
   return 0;
}


// 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
   if(old_cpi<0||new_cpi<0||old_cpi==0)
   {
    return 0;
   }
   return (new_cpi - old_cpi) / old_cpi * 100;
   // Use (new_cpi - old_cpi) / old_cpi * 100

}
rearrange your while loop.
Topic archived. No new replies allowed.