c++ - How to use cin inside a function? -


I am new to C ++ and am trying to create a simple text based game. The code below should welcome the user in the game and ask if the user wants to start the game or not. I did not find any build errors, but when I run it shows that there is a blank screen. What exactly am I doing wrong?

Code below:

  string D1 (string origin) {cin> & Gt; Original; Original return; } Int main () {string decision1; Cout & lt; & Lt; "Welcome to Game Names" & lt; & Lt; Endl; Cout & lt; & Lt; "Do you want to start the game?" & Lt; & Lt; Endl; Cout & lt; & Lt; "Yes / no" & lt; & Lt; Endl; String D1 (Decision 1); System ("cls"); If (decision 1 == "yes") {cout & lt; & Lt; "It happens" & lt; & Lt; Endl; } And if (decision 1 == "no") {cout & lt; & Lt; "It happens" & lt; & Lt; Endl; }}  

You do not have to call D1 D1 :

  std :: string D1 () {std :: string} A new variable named; Std :: cin & gt; & Gt; Original; Original return; } Int main () {std :: cout & lt; & Lt; "Welcome to Game Names" & lt; & Lt; Std :: endl; Std :: cout & lt; & Lt; "Do you want to start the game?" & Lt; & Lt; Std :: endl; Std :: cout & lt; & Lt; "Yes / no" & lt; & Lt; Std :: endl; Auto Decision 1 = D1 (); System ("cls"); If (decision 1 == "yes") {std :: cout & lt; & Lt; "It happens" & lt; & Lt; Std :: endl; } And if (decision 1 == "no") {std :: cout & lt; & Lt; "It happens" & lt; & Lt; Std :: endl; }}  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -