May 22, 2009 at 5:45am UTC
Hey Guys
Just another issue with C++ that I need help with.
How do you program that if the user enters a particular string, an operation occurs.
For example 1: if the user inputs the string 'name', I want the output to be (for instance) "Tom"
For example 2: if the user inputs the sring 'hello', I want the output to be "Nice to meet you"
So how would you perform the functions above and would it be best using an if statement. If so how?
Thanks for your help
Strings are so hard to manipulate aren't they?
May 22, 2009 at 5:52am UTC
Well that doesn't really require any manipulation of the strings, that really just requires comparisons. For something that simple, a switch statement should suffice. Here is how to use them with the examples you gave
1 2 3 4
switch ( input ) {
case ( "name" ): cout << "Tom" << endl; break ;
case ( "hello" ): cout << "Nice to meet you" << endl; break ;
}
etc.
Last edited on May 22, 2009 at 5:53am UTC
May 22, 2009 at 6:01am UTC
Last edited on May 22, 2009 at 6:02am UTC