+ 1
If and else statement arent working properly. Some tip?
the first if statement are giving the wrong result with else condition. c++ #include <iostream> using namespace std; int a; int b; int main() { cout << "insert the first.number \n"; cin >> a; cout << "Insert the second number \n"; cin >> b; if (a > b) { cout << "first number is bigger\n"; if (a < b) { cout << "second number is bigger"; } } else { cout << "the numbers are equal"; } system("pause"); return 0; }
3 Answers
+ 4
Here ya go. Corrected your IF-ELSE logic.
https://code.sololearn.com/c9NnZv14yhIK/#cpp
#include <iostream>
using namespace std;
int a;
int b;
int main()
{
cout << "Insert the first number: \n";
cin >> a;
cout << "Insert the second number: \n";
cin >> b;
if(a == b) {
cout << "The numbers are equal!\n";
} else if(a > b) {
cout << "First number is bigger!\n";
} else if(a < b) {
cout << "Second number is bigger!\n";
}
system("pause");
return 0;
}
+ 3
You're welcome, Andre. Happy learning!
+ 2
Thank you =)