I am trying to write an infix calculator and I want to start the program off asking the user if he/she needs help or not. I have written the code that will offer instructions if the user inputs 'y' or 'n', however, in both cases, the program ends without allowing the user to enter an infix expression and running the rest of the program. It seems as though the program is breaking in main right after cout << "Expression?"; It does not give the option for the user to input anything after that.
1 Answer
When you use cin >> help, you're only reading one character, the y or n. The newline after that is left in the input buffer.
Then when the main function uses getline, it reads up to the next newline, which is the one that was left in the buffer by provideHelpIfNecessary. So it just reads a zero-length line, and that causes the while loop to break.
Use getline in provideHelpIfNecessary instad of reading just one character.
isValidResponse, you're just testing whether its address is not null.