954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help with errors

#include
#include
#include
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<

missy
Newbie Poster
13 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

Code Tags
1. void main() is wrong.

prog-bman
Junior Poster
109 posts since Nov 2004
Reputation Points: 14
Solved Threads: 4
 

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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You