help with if else if statement and characters

This is a discussion on help with if else if statement and characters within the C++ Programming forums, part of the General Programming Boards category; i haven't programmed in c++ in probably two years. i was just bored and trying to make a simple program ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    12

    help with if else if statement and characters

    i haven't programmed in c++ in probably two years.
    i was just bored and trying to make a simple program for myself.
    here is the code i am having some trouble with.
    i know it's probably smething simple, but i just cant figure it out
    and i don't have any books in front of me to look at.

    Code:
    cout << "Did someone else work with you? (y/n)";
        cin >> a;
        {
    		if (a = 'y' || 'Y')
    		{
    			cout << "Enter how many days they helped you: ";
    			cin >> days;
    			help = ((d / 2) * days);
    			cout << "Your helper should be paid: $";
    			cout << help;
    			cout << "                                                                                ";	
    		}
    		else if (a = 'n' || 'N')
    		{
    			return 0;
    		}
    	}

    basically i can't get it to tell whether you enter a y or n.
    everythng i want to run for entering y runs no matter what
    character you enter. help me please...
    Last edited by z.tron; 07-09-2002 at 10:46 AM.

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    > if (a = 'y' || 'Y')

    if (a == 'y' || a == 'Y')

    Remember, = is assignment, == is comparison.

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    12
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. input/switch statement issues
    By peanut in forum C Programming
    Replies: 5
    Last Post: 10-27-2006, 02:58 PM
  2. Can repeated characters be printed with a C statement?
    By Pete_2000 in forum C Programming
    Replies: 4
    Last Post: 05-05-2006, 07:47 PM
  3. Replies: 4
    Last Post: 10-14-2005, 12:53 PM
  4. Using the Switch statement with Characters?
    By Sulaco in forum C Programming
    Replies: 2
    Last Post: 11-18-2002, 12:13 PM
  5. International (scandinavian) characters?
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 01-11-2002, 05:14 PM

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