View Single Post
Old Apr 30th, 2008, 4:12 PM   #4
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: multiple values for one char

not quite, along the right lines though.

I myself would do something like this

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int main ()
  5. {
  6. string correct1 [2] = {"Winston Churchill", "Chruchill"};
  7. string input1;
  8. cout << "Who was the Prime Minister of England during WWII?\n";
  9. getline(cin, input1);
  10. return 0;
  11. }

I understand there may be a few new concepts in there but strings are good to look into for something like this. getline(), may also be new to you. Don't worry have a look at a reference and you should be fine with it.

Once you have got the user's input you will want to look at checking to see if the input matches either of the 2 entries in your array.

C++ Syntax (Toggle Plain Text)
  1. for(int i = 0; i < 2; i++){
  2. if(correct1[i] == input1){
  3. cout << "Congratulations, you got it!";
  4. }
  5. }

I hope none of that confuses you too much.

one final thing to consider is what happens if i type in "winston churchill" or "Winston cHurchill", are these wrong?

i'm happy to explain anything your unclear about

Chris
__________________
Who said i couldn't program
sarcasm = raw_input('Type in a sarcastic remark: ')
print sarcasm
Freaky Chris is offline   Reply With Quote