Loops

I am making a prog to display the largest out of three numbers and i am stuck real bad. Pls help :) Thanx in advance.

// Just Rahul Prog-9
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b=1;
cout<<"\t\tPROGRAM TO FIND LARGEST OF THREE +VE NUMBERS:-";
for(int x=1;x++;x<=3);
{
cout<<"\nEnter a number=";
cin>>a;
if(a>=b);
{
b=a;
}
}
getch();
}
After the loop, output the value of b? It looks like your program is complete already.

Also, do not use conio.h, it is non-standard and deprecated:
https://en.wikipedia.org/wiki/Conio.h
Last edited on
Did just like you said but still the loop doesn't iterate more than once.

// Just Rahul Prog-9
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"\t\tPROGRAM TO FIND LARGEST OF THREE +VE NUMBERS:-";
for(int x=1;x++;x<=3);
{
cout<<"\nEnter a number=";
cin>>a;
if(a>=b);
{
b=a;
}
}
cout<<"Largest number is="<<b;
getch();
}
Last edited on
You never assign any value to b, it just has random memory and could be any number.

Stop using non-standard deprecated headers like conio.h and iostream.h - instead use just <iostream>

Also, main must return int.
Last edited on
Topic archived. No new replies allowed.