Hi, I've just stated learning C++ and i've been reading through the tutorials on this site and messing about with a few programs, but I am having a problem with trying to use an IF statement which gives a certain message depending on whether the user enters 'yes' or 'no' for input.
The program i want to write is like this:
Google didn't find anything even after reading a few tutorials on string variables and the FAQ on this site didn't provide any help either as I just got confused with the usage of the "std::" stuff.Code:#include <iostream> #include <string> using namespace std; int main () { string = "input"; // It won't even compile this part, but some tutorials said it was legal cout<<"Do you want a cookie.\n"; //Just as an example cout << input; cin.ignore(); if ( input == 'yes' ) { cout<<"Here is your cookie.\n"; } else if ( input == 'no' ) { cout<<"O.K, no cookie for you.\n"; } cin.get(); }
Any help would be greatly appreciated.
Calef13



LinkBack URL
About LinkBacks



