How do you make your code want you to type an answer to continue
Nov 14, 2018 at 4:43am UTC
How do you make your code want you to type an answer to continue?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
int main()
{
// Title
SetConsoleTitleA("Game" );
// Login
// Note: I'll do that sometime in the future.
// Menu
cout << "Do you want to play?" ;
cout << "\n" ;
cout << "\n" ;
cout << "Please type 'yes' to continue... " ;
// Pause
cin.get();
// End
return 0;
}
How would I make it so you need to type "yes" to continue?
Last edited on Nov 14, 2018 at 4:46am UTC
Nov 14, 2018 at 2:42pm UTC
For instance:
1 2 3 4 5 6 7
string answer;
do
{
cout << "Please type 'yes' to continue... " ;
cin >> answer;
}
while (answer != "yes" );
Nov 15, 2018 at 12:57am UTC
This is my code so far... How would I make it so it says something after and pauses the terminal?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
int main()
{
// Title
SetConsoleTitleA("Game" );
// Login
// Note: I'll do that sometime in the future.
// Menu
cout << "Do you want to play?" ;
cout << "\n" ;
cout << "\n" ;
string answer;
do
{
cout << "Please type 'yes' to continue... " ;
cin >> answer;
}
while (answer != "yes" );
cout << "Okay!!" ;
// Pause
cin.get();
// End
return 0;
}
Nov 15, 2018 at 7:34am UTC
On line 24 use getline(cin, answer);
instead of cin >> answer;
.
With cin >> answer;
the newline is left in the stream and a following cin.get();
immediately returns.
Topic archived. No new replies allowed.