Small fixes needed.

Hello. I had my final exam today, and decided to write some more practice files so as to stay ready for the next semester. This program has some minor errors I don't quite get.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 #include <ifstream>
int main()
{
   ifstream myfile;("numbers.txt");
   int n,m;
   infile>>n;
   for(int i=0;i<n;i++)
   {
      infile>>m;
      int j=0,dig,a,flag=1;
      while(m)
      {
         dig=m%10;
         m=m/10;
         if(j++==0){a=dig;continue;}
         else if(a<dig) {flag=0;break;}
         else a=dig;
      }
   }
         
      if(flag==1)cout<<"Well-ordered"<<endl;
      else cout<<"Non well-ordered"<<endl;
}

These are the errors:
ifstream: No such file or directory.
In function `int main()':
4 `ifstream' undeclared (first use this function)
4 expected `;' before "myfile"
6 `infile' undeclared (first use this function)
21 `flag' undeclared (first use this function)
21 `cout' undeclared (first use this function)
21 `endl' undeclared (first use this function)


Any help would be greatly appreciated.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
   ifstream infile;
   int n=0,m=0,flag=0;
   infile>>n;
   for(int i=0;i<n;i++)
   {
      infile>>m;
      int j=0,dig,a,flag=1;
      while(m)
      {
         dig=m%10;
         m=m/10;
         if(j++==0){a=dig;continue;}
         else if(a<dig) {flag=0;break;}
         else a=dig;
      }
   }
         
      if(flag==1)cout<<"Well-ordered"<<endl;
      else cout<<"Non well-ordered"<<endl;
}
Last edited on
Topic archived. No new replies allowed.