How would I run this multiple times?
Nov 10, 2015 at 5:01am UTC
When I run this the second time it skips the part where it asks the user to enter the name... how would I bypass this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include <iostream>
#include<conio.h>
using namespace std;
int main ()
{
char again;
const int fullsize = 60;
char fullname[fullsize] = {"" };
do
{
cout << "Enter name: " ;
gets(fullname);
cout << "Your name is " << fullname << endl;
cout << "run again? " << flush;
cin >> again;
} while (again == 'y' );
}
Nov 10, 2015 at 5:10am UTC
You need to flush input buffer with something like cin.ignore (). This is because line 17 leaves a CRLF in buffer and then that is the first thing line 14 sees.
Topic archived. No new replies allowed.