View Single Post
  #4 (permalink)  
Old July 16th, 2005, 03:02 AM
Alan-LB Alan-LB is offline
Authorized User
 
Join Date: Mar 2005
Posts: 58
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to Alan-LB Send a message via Yahoo to Alan-LB
Default

This works OK. Declare x as a char array of 10. Since the word lottery is a string and not a character it must be enclosed in double quotes (").

A better solution would be to define x as a string type.

#include <iostream.h>
void main()
    {
      char x[10];
      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;
      }
    }

Keep reading the book :-)

Alan


Reply With Quote