C++ Help Beginner

// == equals comparing != Equals (First Value != Second value(NOT equal to second value)
// >= Greater than or equal too, <= Less than or equal too

#include <iostream>
#include <conio.h>

using namespace std;

int main(){
int FirstValue;
int SecondValue;

cin >> FirstValue;
cin >> SecondValue;



if(FirstValue==SecondValue){
cout << "Equal!" << endl;


}





else if(FirstValue>SecondValue){
cout << "First Value is greater than the Second Value!" << endl;
}
else if(FirstValue<SecondValue){
cout << "Second Value is greater than the First Value!" << endl;

}

else(FirstValue!=SecondValue);{

cout << "Not Equal!" << endl;
getch();
return 0;
}





}

This is the code, If I put in too matching integers it comes up as "Equal!" as well as "Not Equal!" How can I fix this?
Last edited on
Look through this code snip

else(FirstValue!=SecondValue);{

cout << "Not Equal!" << endl;
getch();
return 0;
}


I will rewrite it that it would be more clear


1
2
3
4
5
6
7
8
else  (FirstValue!=SecondValue);

{
 
cout << "Not Equal!" << endl;
 getch();
 return 0;
}



It consists from two statements. The first one is else with a logical expression and it ends with a semicolon.

The second one is a compound statement.

I think you meant either

1
2
3
4
5
6
else if  (FirstValue!=SecondValue){
 
cout << "Not Equal!" << endl;
}
 getch();
 return 0;



or

1
2
3
4
5
6
else{
cout << "Not Equal!" << endl;
}

 getch();
 return 0;


Topic archived. No new replies allowed.