How do i make it that the user can input a phrase instead of a number

say i want to make a program that needs a phrase and i dont want them to put the number 1 i want them to use the phrase yes or no how can i do this please give me an example.
Try reading up on std::getline() and std::strings.
Hello, learningtocode14.

A program such as the one you described doesn't have to be overly complex. Something like this may serve you well:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <string>
#include <iostream>

int main( )
{
    std::string In_Buffer;

    std::getline( std::cin, In_Buffer, '\n' );

    if( In_Buffer.compare( "Yes" ) == 0 )
    {
        // The strings match.
    }

    else if( In_Buffer.compare( "No" ) == 0 )
    {
        // The strings match.
    }

    else
    {
         // The user entered something that was unexpected.
    }
}
Thank you very much!
Topic archived. No new replies allowed.