Hey all,
I'm writing a program that finds the root mean square of a series of numbers the user inputs. When the user wants to exit the program they will enter -1 and the final answer will be displayed. If the user enters no data (they enter -1 on the first input) then it should display "no data". The trouble I am having is that whenever the user enters -1 both the "Answer" and "no data" are displayed. Does anyone know what I am doing wrong??
I'm sorry...I should be more clear. You're putting cout << "Answer = " << root << endl; outside of the if(number >= 0)while(number != -1) loop. You shouldn't do that, because the way you wrote it, no matter what order you put it in, it will always print.
When I put the cout << "Answer="... statement inside the while loop it prints the "answer =" after each input. I only want it to print when the user exits the program (enters -1).