Coding Help

Hello everyone. I am taking a C++ class at my local community college and our first big programming assignment is due in just a few days. I have all my code written and it does what it is supposed to do and looks how it is supposed to look. However, I want to add one more item. And what I am wanting to do, I am pretty sure we have not covered in class yet.

If anyone remembers WOPR from the movie Wargames, he would ask "Hello, would you like to play a game?"

I have the line, but here is where I need the help.

I need the user to input either Y or N and no matter what they pick, I then need it to move on to the actual assignment. This one line and action is mainly for our teachers amusement.

1
2
3
4
5
cout << "Hello, would you like to play a game?" << endl;
	
	// Get the student name
	cout << "Enter the name of the student: ";
	getline(cin, studentName);


So as stated, right after the first cout is when I would like the Y or N and then have it move on to the next cout.


Thanks!!

BCoop
You can use:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cout << "Hello, would you like to play a game?" << endl;
	
    char input_ans;

    cin >> input_ans;

    if(input_ ans == 'Y' || input_ans == 'y')
        // do something

    else
        // do something else
       
    // Get the student name
    cout << "Enter the name of the student: ";
    getline(cin, studentName);
Last edited on
Topic archived. No new replies allowed.