+ 1
Can any please tell me what I am doing wrong
#include <iostream> void main() {int x, y, z, l; cout << " Enter three number"<< "\n"; cin >> x >> y >> z ; if (x>y) l = x ; else l = y ; if (l > z) cout << "The greatest number is " << l; else cout << "The greatest number is " << z; }
3 Answers
+ 1
Hi, your code is close.
The first problem is that you are not using the std name space, either add std:: in front of cin and cout or add using namespace std; at the top of your file after your includes.
Second its good practice to return int from the main function and return 0; at the end of main assuming execution finished without errors.
White space to indent code makes it easier to read also.
All your other logic works the way it is however you could simplify it a little.
here is a working version of your code:
#include <iostream>
using namespace std;
int main()
{
int x, y, z, l;
cout << " Enter three number"<< "\n";
cin >> x >> y >> z ;
if (x>y)
l = x ;
else
l = y ;
if (l > z)
cout << "The greatest number is " << l;
else
cout << "The greatest number is " << z;
return 0;
}
0
First, you have to add "using namespace std;" at the beginning
- Prefer using a "cin" per variable
- Using {} for if and else
0
Thanks u Andrew and Geoffrey