Simple question with programming

This is a discussion on Simple question with programming within the C++ Programming forums, part of the General Programming Boards category; Im trying to make a simple program in console to ask what you would like to do. and you answer ...

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    2

    Exclamation Simple question with programming

    Im trying to make a simple program in console to ask what you would like to do. and you answer and the program check the answer and if it is "this" then it will say something but anything else will say something else.

    this is the actual details of the problem

    /////////

    char Question = ''; <------idk what to assign here to correct tell it to grab.

    Code:
    cout << "What would you like to do first?\n";
     cin >> Question;
                                   if ( Question == 'sleep' )
    			{
    			cout << "Goodnight then" << endl;
    		                qQ = true;   <---- just a boolean to tell the computer to stop looping
    			}
    			
    		else
    cout << "I don't know what " << Question << " is." << endl;
    		}
    the format might look wrong but when i run it states the question and i put fly
    ive got it on a loop until the right answer is said but when i put wrong answer i get this

    it says
    i dont know what f is.
    i dont know what l is.
    i dont know what y is.

    i think im using the wrong assigment CHAR. is there something else i can use to store whatever the user puts in cin? sorry if this is confusing. hope you can help!

  2. #2
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    A char only holds one character, you should include the header <string> at the start of your program and change the 'Question' variable to 'string', a string will hold more than one letter, which is what you want in this case.

    Also, the 'sleep' in the if statement should be enclosed by quotation marks, like this:
    Code:
    if ( Question == "sleep" )
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    2
    thanks that worked perfectly

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 08:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 11:15 AM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 05:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21