Thread: Variables, Strings

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    2

    Arrow Variables, Strings

    I know this may look sad but...Could you help me?

    Here is my code, how do I make this work... I want it so if you press y it says "Good, you may enter the program!" and if you press n it says "You're not an Anime fan?!". Once again here is my code:

    #include <iostream.h>
    int main()
    {
    int fan; ..
    cout<<"Please tell me, are you an Anime fan? (y/n): ";
    cin>>fan;
    if(fan=='y')
    {
    cout<<"Good, you may enter the program!";
    }

    else
    {
    cout<<"You're not an Anime fan?!";
    }
    return 0;
    }


    I crave C++ knowledge.

  2. #2
    Still A Registered User DISGUISED's Avatar
    Join Date
    Aug 2001
    Posts
    499
    << int fan; ..

    Fan should be of type char, and lose the two periods as well.

  3. #3
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    uhh, since this is a simple program i dont think it would hurt just to show you:

    Code:
    #include <iostream.h>
    
    char fan;
    
    int main()
    {
          cout<<"Are you an anime fan? (y/n) ";
          cin>>fan;
    
                     if( fan == 'y'){
                           cout<<"Yay, youre an anime fan!";
                      }
                     else if( fan == 'n'){
                           cout<<"No, you cannot continue!!!";
                     }
                     else{
                           cout<<"Enter y or n";
                     }
    getchar();
    return 0;
    }
    You might need a different header for that "getchar()" function. I cant remember right now. But that just stalls the program until enter is pressed.
    What is C++?

  4. #4
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    oh and for the future, use the code tags....
    What is C++?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  2. Problems with strings as key in STL maps
    By all_names_taken in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:34 AM
  3. Craps Program with Local Variables
    By tigrfire in forum C Programming
    Replies: 12
    Last Post: 11-09-2005, 09:01 AM
  4. Variables TO Strings
    By Okiesmokie in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 11:06 PM
  5. turning variables into strings
    By jagerhans in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2001, 02:10 PM