/*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;
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
#include <iostream>
usingnamespace 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
}
// 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.