English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

//Sample Program 12- A non-interactive program to calculate student grades.
//**************************************************************************************

#include
#include
#include
#include
using namespace std;

const int SIZE=20;

int main()
{
int exam1Array[SIZE];
int exam2Array[SIZE];
int exam3Array[SIZE];
int highScore;
int count=0;
string name[SIZE];
ifstream inFile;

inFile.open("grades.dat");
if(!inFile)
{
cout<<"Unable to open input file, program abnormally ended";
return 1;
}

inFile>>name[count]>>exam1Array[count]>>exam2Array[count]>>exam3Array[count];
highScore=0;
for(count=0; count
if(array[count]>highScore)
highScore=array[count];


cout< return 0;
}

2006-07-31 10:55:35 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

It is supposed to read an input file containg student name, and Exam 1 score, Exam 2 score, Exam 3 score.

I'll add other fucntions later for other calculations. At this stage i just want it to read the file and find the highest in each exam and output the highest for each exam. I am having difficulty with the code and the looping. I am self-studying so it's a bit challenging at times. Please help!! THANKS!!

2006-07-31 10:57:59 · update #1

inFile>>name[count]>>exam1Array[count]>>exam2Array[count]>>exam3Array[count];
highScore=0;
for(count=0; count
if(array[count]>highScore)
highScore=array[count];


cout< return 0;

2006-07-31 10:58:59 · update #2

inFile>>name[count]>>
exam1Array[count]>>
exam2Array[count]>>
exam3Array[count];
highScore=0;
for(count=0; count

2006-07-31 10:59:52 · update #3

4 answers

in your loop, you forgot the brackets. change:

for(count=0; count
if(array[count]>highScore)
highScore=array[count];

cout< return 0;

to

for(count=0; count {
if(array[count]>highScore)
{
highScore=array[count];
cout< }
}
return 0;

2006-08-01 01:26:21 · answer #1 · answered by justme 7 · 0 0

The following code will work in VC++ 2005:
[Create a new Win32 Console Project]

#include "stdafx.h"
const int SIZE=20;

int _tmain(int argc, _TCHAR* argv[])
{
float exam1Array[SIZE];
float highScore = 0.0;
int count=0;
int error;
FILE * inFile;

fopen_s(&inFile,"c:\\temp\\junk\\grades.dat","r");
if(feof(inFile))
{
printf("Unable to open input file, program abnormally ended");
return 1;
}

fseek(inFile, 0L, SEEK_SET );
while (!feof(inFile))
{
error = fscanf_s(inFile,"%f",&exam1Array[count]);
if (exam1Array[count] > highScore)
highScore = exam1Array[count];
count++;
}

fclose(inFile);
printf("Highest Score is = %f",highScore);
getchar();
return 0;
}

The grades.dat file should look like:

53.5
84.2
98.1

with no Carriage return after the last grade.
This is something you can play with in the mean time. Happy learning! Remember to give me points for this...

2006-07-31 12:42:17 · answer #2 · answered by Anonymous · 0 0

buy K&R book on C called "The C Programming Language, Second Edition".. it has all this easy stuff in it... if you are starting with C .. you should really have this book... it is the basis of all C

2006-07-31 11:00:19 · answer #3 · answered by K of the G 3 · 0 0

Are you really supposed to go online to get others to do your assignments for you?

2006-08-01 04:59:17 · answer #4 · answered by Donna DiaWana 3 · 1 0

fedest.com, questions and answers