c++ else if is skipped?

how do i change the code such that it wont skip the else if and if statements.
whether i enter 5 , 2 ,3 or other integer , it just says value1 equals value2
its coded with dev c++ .
any help will be appreciated , thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  #include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int val1;
    cout << "enter value1" << endl;
    cin >> val1;
    int val2;
    cout << "enter value2" <<endl;
    cin >> val2;
    
    if (val1 = val2)
    {
    cout << "value1 equals value2" << endl;
    }
    else if (val1 > val2)
    {
    cout << "value1 is larger than value2" << endl;
    }
    else 
    {
        cout << "value1 is smaller than value2!" << endl;
    }
    system("PAUSE");
    return EXIT_SUCCESS;
}
if (val1 = val2)

= is the assignment operator
== is used to test for equality

The compiler may issue a warning for this - the compiler can't tell for certain that the code is wrong - only the programmer knows that.
Last edited on
omg it works! thanks very much
Topic archived. No new replies allowed.