In the code below, the first function gets input from the user and the second function is suppose to do some calculation and display an answer. However, I keep getting "-1.#NID" where the answer should be. Please help.
while calling the get_input function, the arguement "current_price" and 'past_price' are not yet initilized(they don't exist yet). so you cant use them as arguement to call the function:
in do function
1 2 3 4 5 6 7 8 9 10 11 12 13 14
do
{
cout << "Please enter the current price of an item:\n";
cin >> current_price;
cout << "Please enter the past price of an item\n";
cin >> past_price;
display_results(current_price, past_price);
cout << "\n";
cout << "Run the program again?(Type Yes or No.)\n";
cin >> answer;
}while(answer == "Yes" || answer == "yes");
and delete the get_input function. should work like a charm.
well, in that case you could use either a pointer or just function inside a function. I am just guessing that you haven't reached to pointer yet. so another way it is;
@koopey
- they arent initialized, but they do exist. i dont know who told you they dont.
- you can use unitialized variables in an argument
- do is not a loop
@op: using namespace std; and global variables are bad. i suggest looking into passing by reference instead of global variables.
@Little Bobby Tales
- I meant to say that they don't contain the value that we want, just random number is stored in the memory of the variable. I used
they don't exist
in kind of literary sense to make it easier to understand and didn't realize 'exist' could be perceived in other ways.(which i now realize are true and more plausible)
- I don't understand how 'do' is not a loop(among others as while and for)
- continued program using global variable feeling that OP wanted it that way for sake of convenience.
- I didn't know using namespace std is bad practice. I use jumping into c++ and same is used in every of its sample program, at least till now.