View Single Post
  #1 (permalink)  
Old July 14th, 2005, 07:49 PM
dovids dovids is offline
Registered User
 
Join Date: Jul 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default "C++ lottery" with letters and words

I'm reading Wrox's "Beggining programming" and in chapter seven the author brings some code that works perfectly, both in the compiler and the .exe:

Code:
#include <iostream.h>
void main()
    { 
      int x;
      cout << "Pick an integer: ";
      cin >> x;
      if (x == 7)
      {
        cout << "You win the C++ lottery!" << endl;
        cout << "Thank you for playing the C++ lottery" << endl;
      }
      else
      {  
        cout << "Thank you for playing the C++ lottery" << endl;
      }
    }


My question is, how it is possible to write the same mini-program but picking up a letter instead of a number. Let's say, that by picking up the letter "a" or the word "lottery" I win the "C++ lottery". I tried to write this code (see bold type)

Code:
#include <iostream.h>
void main()
    { 
      int x;
      cout << "Pick a word: ";
      cin >> x;
      if (x == lottery)
      {
        cout << "You win the C++ lottery!" << endl;
        cout << "Thank you for playing the C++ lottery" << endl;
      }
      else
      {  
        cout << "Thank you for playing the C++ lottery" << endl;
      }
    }


And the compiler found this code mistaken . Any suggestions on how to code this properly?

Thank you for your time :D. I would appreciate very much an answer to this .
Reply With Quote