0
#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();
 }
}

Edited by pyTony: fixed formating

3
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by Narue
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.