My code doesn't work properly
What's wrong with my code? It always displays the last number!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include<iostream>
using namespace std;
int main()
{
bool flag=true;
int x, max, count=0;
cout<<"Enter a number: \n";
cin>>x;
max=x;
while(flag)
{
cout<<"Enter a number: \n";
cin>>x;
if(x>max);
max=x;
count++;
if(count >=3)
flag = false;
}
cout<<"max is"<<max;
return 0;
}
|
You have an errant ; on line 15. Should be if(x>max)
Ohh right! Now fixed. thanks
Ramp up the warnings in your compiler (see your other thread)
|
In function 'int main()': 15:12: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
|
Topic archived. No new replies allowed.