if statement problemos

This is a discussion on if statement problemos within the C++ Programming forums, part of the General Programming Boards category; i'm trying to make a program that's menu-based that will perform addition, subtraction, multiplication, or division, but I can't get ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    2

    if statement problemos

    i'm trying to make a program that's menu-based that will perform addition, subtraction, multiplication, or division, but I can't get the if statement to work correctly, and i'm pretty sure i'm doing something horribly wrong. my failure of a code is attached. please help!
    Attached Files Attached Files

  2. #2
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Code:
    if(operation == '+' )
      		   no1 + no2 == result;
      		  else if(operation == '-')
      			  no1 - no2 == result;
      			  else if(operation == '*' )
      				  no1 * no2 == result;
      				  else if(operation == '/')
      					  no1 / no2 == result;
    That is where your problem is...
    have you read assignment?

    And also, enter valid data into variables before performing operations on it :P
    Last edited by Eman; 01-17-2011 at 09:17 AM.
    You ended that sentence with a preposition...Bastard!

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Code:
      no1 / no2 == result;
    Backwards ... the variable holding the result always goes on the left of the assignment operator.

    Wrong operator... == is a comparison ... = is an assignment.

  4. #4
    Registered User
    Join Date
    Jan 2011
    Posts
    2
    thanks guys!

  5. #5
    Registered User
    Join Date
    Jan 2011
    Posts
    5
    And from what I know, the variable you are changing the value of should come first, like:

    a=3+4,
    not
    3+4=a.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why won't this simple statement work?
    By nick753 in forum C++ Programming
    Replies: 10
    Last Post: 10-19-2010, 12:20 AM
  2. bizarre print statement glitch
    By spongefreddie in forum C Programming
    Replies: 4
    Last Post: 09-23-2010, 11:39 AM
  3. Replies: 3
    Last Post: 08-16-2010, 11:00 AM
  4. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 06:19 AM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM

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