If and else statement arent working properly. Some tip? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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; }

22nd Mar 2018, 4:28 PM
Andre Costa
Andre Costa - avatar
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; }
22nd Mar 2018, 4:35 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 3
You're welcome, Andre. Happy learning!
22nd Mar 2018, 4:46 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 2
Thank you =)
22nd Mar 2018, 4:43 PM
André Costa
André Costa - avatar