interesting to try.......Asist me!

/*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*/

#include <iostream>
using namespace std;

// declaring a function
double calculate_Inflation ();

int main()
{
double yearAgo_price, currentYear_price , pric1, price2 ;

cout << "Enter the current price \n" ;
cin >> currentYear_price ;

cout << "Enter the previous year price \n";
cin >> yearAgo_price;

cout << "Inflation = " << calculate_Inflation ( ) ;
}
// defining the function
double calculate_Inflation (double price1 , double price2)
{
return ((price 2 - price 1)/price1)/100);

} //inflation
Was there a question somewhere?
You don't pass anything to calculate_Inflation(price1, price2)
main() should return 0 (or anything else). It's function, and functions have to return stuff (except void ones)
Why are you declaring pric1 and pric2?
 
double yearAgo_price, currentYear_price , pric1, price2 ; // you don't need price1 or price2 here 



1
2
3
4
5
6
7
double calculate_Inflation (double price1 , double price2)
{

return( ( price 2 - price 1 ) / price1 ) /100 ); // You can't space the '2' and the '1' they have to be like this return( ( price2 - price1 )  / price1 ) / 100 );

} //inflation
try this way. I commented the changes.
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
#include <iostream>
using namespace std;

// declaring a function
double calculate_Inflation ();

int main()
{
double yearAgo_price, currentYear_price; //You dont need price1 or price 2

cout << "Enter the current price \n" ;
cin >> currentYear_price ;

cout << "Enter the previous year price \n";
cin >> yearAgo_price;

cout << "Inflation = " << calculate_Inflation (yearAgo_price, currentYear_price); //You need to pass the parameters to the function so the function can return something back

  return 0;  //Main function has to return something....
}
// defining the function
double calculate_Inflation (double price1 , double price2)
{
return ((price2 - price1)/price1)/100); //No spaces on variable names price 1 and price 2
}
Last edited on
// I tried this from orejano but geting an error, too many arguments to function 'double calculate_inflation'

#include <iostream>
using namespace std;

// declaring a function
double calculate_Inflation ();

int main()
{
double yearAgo_price, currentYear_price; //You dont need price1 or price 2

cout << "Enter the current price \n" ;
cin >> currentYear_price ;

cout << "Enter the previous year price \n";
cin >> yearAgo_price;

cout << "Inflation = " << calculate_Inflation (yearAgo_price, currentYear_price); //You need to pass the parameters to the function so the function can return something back

return 0; //Main function has to return something....
}
// defining the function
double calculate_Inflation (double price1 , double price2)
{
return ((price2 - price1)/price1)/100); //No spaces on variable names price 1 and price 2
Are you sure you wrote the code correctly?. It looks like you are passing too many arguments to function calculate_inflation, you need to pass two arguments only.
Topic archived. No new replies allowed.