#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void main()
{
 ifstream indata;
 ofstream outdata;
 char name [13][20];  
 float avg[20];     
 int sum=0, n, i=0, m,p;
 float davg;
char ch;
indata.open("a:nameFile.txt"); 

 if(indata.fail())
 {
    cout<<"file not open:";
    exit (1);
 }
 while(i<=20)
 {
  for (i=0;i<20;i++)

    indata.getline(name[i],20);
 }

  for (int k=1; k<=3; k++)

  {
   indata  >> n>>m>>p;
   avg[i]=n+m+p/3;
    indata.get(ch);

  davg = sum/3;
  avg[i] = davg;
  sum=0, n=0, davg=0, i++;
  indata.ignore();
 }
 cout<<"enter a grade value:\n";
 cin>> n;
 outdata.open("outfile.txt", ios::out);

 for(int k=0; k<20; k++)
 {
  if(avg[k]>=n)
   outdata<<name[k]<<"  "<<avg[k]<<endl;
  outdata.close();
 }
}

Code Tags
1. void main() is wrong.

You want help with errors yet you don't use code tags and you don't tell us what the errors are. All I get when I compile are warnings that suggest inaccurate behavior. These statements:

avg[i]=n+m+p/3;
davg = sum/3;

Should be changed to this:

avg[i]=n+m+p/3.0f;
davg = sum/3.0f;

This forces the expression into the float range so that anything past the radix is not truncated as it would be using integer math.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.