assign values to charechter variables

This is a discussion on assign values to charechter variables within the C++ Programming forums, part of the General Programming Boards category; Hello, I dont know if you give help with this type of question or not but i thought it would ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    30

    assign values to charechter variables

    Hello, I dont know if you give help with this type of question or not but i thought it would be worth a shot. The program I am creating has functions and stuff. I know how to do all of that. My problem occurs when it comes to calling up the functions. The progrtam has 2 different types of functions to call up or the third option is to quit. I have the functions created and I am just trying to write a fake program that will call up the functions. Instead of calling up the functions right now i am just trying to get the program to output 3 different lines depending on the user input. I give the user the choices of entering the letter 's', 'r', or 'q' as their choice. I have it declared as char choice; When I try to compile the program it says: 's' undeclared (first use this function). It also says the same for q and r. someone told me that I have to assign values to charechter variables and I dont know if that is correct and if so how do i do that? I appreciate any help or response

  2. #2
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    post some code I think I know what's wrong.

  3. #3
    Former Member
    Join Date
    Oct 2001
    Posts
    955
    Try these:

    Make sure that when you're checking if it's equal, use double equal signs ==

    Make sure that you're comparing the input to a character constant, I mean single-quoting it, for example, if you do

    if(input==r)
    {
    }

    is different than doing the right one:
    if(input=='r') <----- Check the single quote
    {
    }


    Good luck

    Oskilian

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    30

    here is what i have for the code

    This is what I have in the body of the code. When i try to compile it i get a message that says: 's' undeclared and I also get that same statement for r and q. any help is greatly appreciated.


    char choice;
    std::cout <<"Enter in the letter s to find out if a specific year is a leap year,";
    std::cout<<"Enter in the letter r to find the number of days in a range of years,";
    std::cout<<"Enter in the letter q to quit the program: ";
    std::cin >>choice;

    if (choice == s)
    std::cout<<"You chose to find out if a year is a leap year."<<endl;
    else if (choice == q)
    std::cout<<"You have chose to quit the program."<<endl;
    else if (choice == r)
    std::cout<<"You have chose to find the number of days in a range of years."<<endl;
    return 0;

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    30
    O.k. thanks to the reply from oskilian i figured out. Thanks you everyone for the help.

  6. #6
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    that's what I thought.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 09-30-2008, 03:12 AM
  2. Replies: 2
    Last Post: 07-03-2008, 12:31 PM
  3. Replies: 1
    Last Post: 12-30-2007, 10:08 AM
  4. 3-d array assign string values
    By WaterNut in forum C++ Programming
    Replies: 8
    Last Post: 07-01-2004, 01:02 AM
  5. Undefined variables have values???
    By Tronic in forum C++ Programming
    Replies: 10
    Last Post: 03-29-2004, 03:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21