0

What is wrong with this c++ code?

#include <iostream> using namespace std; int main() { int a; cout << "a is" << endl; cin >> a; int b; cout << "b is" << endl; cin >> b; if (a > b) { cout << "greatest is " << a << endl; } if (b > a) { cout << "greatest is " << b << endl; } }

17th Jun 2018, 8:27 PM
Devesh Mungad
3 Antworten
+ 1
Error: You're printing a and b on the console before it is defined in line 6 and 9. To avoid this, swap 6th and 7th, and swap 9th and 10th line!
17th Jun 2018, 8:32 PM
777
777 - avatar
0
you have put two if it is worng but you have to put if and else like this👇 if (a>b) { cout<<"greatest is a:"<<a<<endl; } else(b>a) { cout<<"greatest is b:"<<b; }
30th Jun 2018, 7:24 AM
Amaan Saiyed
Amaan Saiyed - avatar
0
My suggestion is to :- 1. First set all the variables at the beginning after "int main (){" 2. Then you can then get user input with the "cin >>". 3. Now use the "if else" statements and there respective conditions. !! Hope it helped !!
30th Jun 2018, 7:36 PM
LJ_Smart
LJ_Smart - avatar