help with errors

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2004
Posts: 13
Reputation: missy is an unknown quantity at this point 
Solved Threads: 0
missy missy is offline Offline
Newbie Poster

help with errors

 
0
  #1
Feb 17th, 2005
#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();
}
}
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 108
Reputation: prog-bman is an unknown quantity at this point 
Solved Threads: 3
prog-bman prog-bman is offline Offline
Junior Poster

Re: help with errors

 
0
  #2
Feb 17th, 2005
Code Tags
1. void main() is wrong.
Join me on IRC:
Server: irc.daniweb.com
Channel: #C++

Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 715
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: help with errors

 
0
  #3
Feb 17th, 2005
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:
  1. avg[i]=n+m+p/3;
  2. davg = sum/3;
Should be changed to this:
  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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC