Inflation Problem.... Cant figure out how to fix it!

Write a program to gauge the rate of inflation for the past year. The program asks for the price of an item (such as a hot dog or a one-carat diamond) both one year ago and today. It estimates the inflation rate as the difference in price divided by the year-ago price. Your program should allow the user to repeat this calculation as often as the user wishes. Define a function to compute the rate of inflation. The inflation rate should be a value of type double giving the rate as a percentage, for example 5.3 for 5.3%.

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
  
#include <iostream>

using namespace std;

double calculate_inflation(double, double);

int main()
{
double yearAgo_price = 0.0;
double currentYear_price =0.0;
double inflatation_Rate=0.0;
char again;

cout << endl;
cout << "What was the price of the item a year ago? ";
cin >> yearAgo_price;
cout << endl;
cout << "What is the price of the item today? ";
cin >> currentYear_price;
cout << endl;

double inflation_Rate = calculate_inflation(yearAgo_price, currentYear_price);
cout << "The inflation rate is " << (inflation_Rate*100) << "%.";
cout << endl;

system ("pause");
return 0;
}

bool(check_for_prices)
{
	cout<< "Do you want to continue (Y/N)?";
        cout<< "Please Press Y to continue or N to exit." << endl;
        cin >> again;
 }
 while((again=='Y')&&(again=='y'));


double calculate_inflation (double oldPrice , double newPrice)
{
	return ((newPrice - oldPrice) / oldPrice);
}
1
2
3
4
5
6
7
8
9
//i dont see you using this function any where
bool(check_for_prices)  //defining a function below main must have a declaration above main
{
        cout<< "Do you want to continue (Y/N)?";
        cout<< "Please Press Y to continue or N to exit." << endl;
        cin >> again;
 }
 while((again=='Y')&&(again=='y'));   //again's scope is only limited to main,
                                        //and your while loop is not part of any scope 


for repeation, just use a do while loop.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main()
{
    do
    {
       //all that stuff in main,

       //what you wanted check_for_prices to do
       cout<< "Do you want to continue (Y/N)?";
       cout<< "Please Press Y to continue or N to exit." << endl;
       cin >> again
    }while((again=='Y')||(again=='y'));  //take not of the change from && to ||
                                        //again can never be 'Y' and 'y' at the same time

    system("pause");
    return 0;
}
Last edited on
On line 23 remove double //You declared it twice

Line 31 - 37... None of this code is being used since it is outside of the main function
and it has syntax errors.. I would just suggest deleting it
Topic archived. No new replies allowed.