So I am new to c++ and we just learned functions. My program always gives back answers like -6.98765e24 and I can't seem to track down why. It might be something in my function or something else, like I said I really don't know that much about writing programs. Thank you!
#include <iostream>
#include <cmath>
using namespace std;
do
{
cout << "Enter the price of an item today\n";
cin >> pricetoday;
cout << "Enter the price of that item one year ago\n";
cin >> pricepast;
cout << "The inflation rate is: " << rate << " percent.\n";
cout << "Do you want to calcluate the inflation on another item?\n";
cout << "Press y or n and then press enter\n";
cin >> answer;
} while ((answer == 'y') || (answer == 'Y'));
cout << "End program." <<endl;
}
Nowhere in your code do you ever actually call your rate() function. Also, nowhere in your code do you ever assign a value to the local variable also called rate in your main function. So you're just printing out whatever value happens to be in that memory location.