Can someone PLEASE correct my code?

I-ll highlight the lines considered wrong by the computer.

#include<fstream.h>
ifstream fin("case.in");
ofstream fout("case.out");
int main()
{int n,cn,max,m,x,i;
fin>>n;
while(n>0&&n<=9)
{
max=0;
x=1;
cn=n;
while(cn>0)
{if(cn%10>max)
max=cn%10;
x=x+1;
cn=cn/10;}
m=max;
for(i=0;i<x,i++)
{m=m*10+max}
cn=n;
n=m-cn;
}
fout<<n;
fout.close();
return 0;
}
What errors and warnings are you getting from the compiler?

Note that a for statement is of the form

for( init conditions ; term conditions ; increment ) ...

So it expects 2 semicolons!

Andy

P.S. #include <fstream.h> suggests you are using a ancient compiler. Nowadays people use the modern <fstream> (there are no .h file exts for the standard library headers)
Last edited on
Topic archived. No new replies allowed.