question

when i type 8 and 22 or anything
it wont comes up and disappear
am i type something wrong?
i suppose to have if it is 8 and 22 or 8 and 8
will come up 8 > 22 , 8 == 8

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  #include<iostream>
using namespace std;

int main(){
	int number1;
	int number2;
	cout << "Enter two integers to compare: ";
	cin >> number1 >> number2;

	if (number1 == number2)
		cout << number1 << " == " << number2 << endl;

	if (number1 > number2)
		cout << number1 << " > " << number2 << endl;

	return 0;

}
Code works fine: https://ideone.com/nM0R19

will come up 8 > 22

8 is less than 22, not more.
closed account (48T7M4Gy)
You haven't covered the case where number1 < number2.
Try another if

Or better if ... else
Or even better if ... else if ... else
even i type another cases still not work but my friend type as the same thing and he work , he doesn't need another cases at all.

my homework is to write a program that asks the user to enter two integers , obtains the numbers from the user , then prints the larger number followed by the words "is larger."if the numbers are equal, print the message "these numbers are equal."
closed account (48T7M4Gy)
You code runs in the shell. Just press the gear wheel on the RH top corner of the text box in your post above.
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<iostream>
using namespace std;

int main(){
	int number1;
	int number2;
	cout << "Enter two integers to compare: ";
	cin >> number1 >> number2;

	if (number1 == number2)
		cout << number1 << " == " << number2 << endl;

	if (number1 > number2)
		cout << number1 << " > " << number2 << endl;
	else
	    cout << "Phone a friend\n";

	return 0;
}



Enter two integers to compare: 2
2
2 == 2
Phone a friend


Also I don't think it is a good idea to have cin >> .. >> ..
It's better to have two separate cout prompts and two separate cin's, one after each prompt. That way you get some feedback instead of a blank screen until you get the input right.
Topic archived. No new replies allowed.