944,093 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1914
  • C++ RSS
Feb 17th, 2005
0

help with errors

Expand Post »
#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();
}
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
missy is offline Offline
13 posts
since Nov 2004
Feb 17th, 2005
0

Re: help with errors

Code Tags
1. void main() is wrong.
Reputation Points: 14
Solved Threads: 4
Junior Poster
prog-bman is offline Offline
108 posts
since Nov 2004
Feb 17th, 2005
0

Re: help with errors

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:
C++ Syntax (Toggle Plain Text)
  1. avg[i]=n+m+p/3;
  2. davg = sum/3;
Should be changed to this:
C++ Syntax (Toggle Plain Text)
  1. avg[i]=n+m+p/3.0f;
  2. 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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Stacks in C++
Next Thread in C++ Forum Timeline: sorry I'm so dumb at this





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC