Hello there,
I was trying to find similar question about this statement, but wasn’t unable to locate on. Still, I am sorry for posting this again in case this question has been answered somewhere already.
String Guess = “”;
Can someone explain me why are we giving value to the variable Guess in Lection 22. - Variables and cin for Input? (I hope I properly addressed what is the variable and what is the value in this example ).
Parallel with the udemy lessons I started reading the tutorial for c++ on www.learncpp.com. And if I understood correctly, if we state variable in our code, we are basically assigning memory slot to it. And we can always put value to it latter in the code, which we did in this statement:
cin >> Guess;
The value should be players input in console, right? Please correct me if I am wrong. This is my way of learning, asking question where I fail to see logic.
Until player gives an input, variable Guess in an uninitialized variable, am I right?
I tried running the code with and without giving it a variable (String Guess; and String Guess = “” and I got the same output.
Can someone explain me why was important assigning “empty” value to the string Guess;?
Just for the context of the question here is the part of the code I am talking about:
//get a guess from player
cout "Enter your guess: ";
string Guess = “”;
cin >> Guess;
cout << "Your guess wass: " << Guess;