Hey everyone. I'm a beginner at C++ and I'm trying to learn about prototypes. I'm having a problem where the program recognizes the prototype however it will not execute it. I would really appreciate it if someone can explain what it is that I'm doing wrong. "void greetUser" will execute. "double computeInflation" will not.
cout << endl << endl << "Please enter the current price of the item: $";
cin >> C;
cout << endl << endl << "Please enter last years price for the item: $";
cin >> L;
computeInflation(C, L);
inflation = inf1;
cout << endl << endl << "Please enter the price two years ago for the item: $";
cin >> T;
computeInflation(L, T);
inflation = inf2;
if (inf1 > inf2)
cout << "Inflation is on the rise" << endl;
else if (inf2 > inf1)
cout << "Inflation is on decline" << endl;
else
cout << "There is no inflation" << endl;
system("PAUSE");
return 0;
}
void greetUser()
{
cout << "Welcome to Inflation Calculator 1.0" << endl;
cout << "====================================" << endl;
cout << "Please enter the current price, last years price, and the price two years ago for the item when prompted." << endl;
}
The computeInflation() function is executing as expected, I'm sure. You're just not doing anything with the value the function returns. You seem to be expecting it to somehow magically get copied into inf1 and inf2.
The program is both recognizing and executing the function; you're just not storing its returned value anywhere. So instead of what you have currently:
Thanks for the help Keene!! When I was debugging the values in the function didn't change so I figured it wasn't executing. What you did makes a lot of sense though and now it runs as expected.
Also, thanks for the compliment! It made my day :)