I'm trying to get back into C++ and am finally adjusting to non-object-orientated code again... but I'm having an issue I can't find an answer too online or through comparison with similar code.
My goal is a simple branching decision and name declaration (which I'm aware can be made more modular to better suit being re-used for other values - I'll work on that whilst I await a response).
The problem: When I compile the script, what I get responds correctly though I have to respond twice to "What is your name?" before it will continue on to the next line. Anybody able to highlight what I've overlooked?
std::string nameDeclare() /// ===** TARGET FUNCTION I CALL LATER IN SCRIPT **==
std::cout << "What is your name?" << std::endl;
std::cin >> namechange;
std::cout << "Initialising..." << std::endl;
nameDeclare(); /// ===** SCRIPT SEEMS TO REPEAT THIS LINE ....or..... THE FUNCTION ABOVE "nameDeclare()"
std::cout << ("You said..." + nameDeclare()) << std::endl;
std::cout << "Is that right?";
std::cin >> x;
if (x == ("No","no"))
std::cout << "Excellent!";
/* For some reason the script repeats the question of "what is your name?" consistently saving the response string 2nd time around and repeating it back correctly.*/
I structured the decision like you suggested originally but for some reason it wasn't working so I assumed the syntax wasn't right and the way posted worked -shrugs-.
Fantastic! I'm just trying to get my head around return values and knew my method was incredibly bloated, I understood what you've done - much appreciated!!
I originally suspected my cout with + nameDeclare might be causing it to run a 2nd time though because it was printing the string correctly 2nd time around I dismissed it. I'll correct it to your suggested layout and better lay out the called function itself.