D4, D5, for 37 students from a file called marks.txt, then use a function to determine
the average grade for each student. Let the main program prints the student number, the
total grades and the average for each student.
the file marks.txt is like that:
1
20
30
40
50
60
2
11
22
33
44
55
3
33
44
55
96
98
4
85
88
70
60
55
5
90
80
70
60
50
6
68.5
99.9
100
55
33
7
66.6
44.5
70
30
60
8
95.5
88
84
58
60
9
55.5
70
77
60
20
10
50
30
20
40
95
11
90
80
70
60
55
12
33
44
55
66
77
13
37
29
70
59
40
14
69
25
49
55
90
15
59
79
85
95
60
16
80
85
30
20
95
17
28
49
56
64
28
18
24
93
84
43
95
19
53
74
83
95
91
20
29
19
39
48
45
21
89
45
30
57
34
22
44
58
38
67
71
23
38
57
38
47
23
24
92
82
72
93
64
25
57
48
29
47
19
26
85
36
77
33
76
27
21
31
91
82
53
28
90
32
35
78
54
29
11
22
33
44
55
30
80
40
50
60
70
31
35
25
15
26
27
32
93
94
75
86
92
33
76
84
39
47
39
34
74
93
85
73
22
35
88
99
66.5
84.5
30.4
36
77.4
33.4
76.5
99
44
37
55
23
45
92
44.5
i've done every thing except the function needed above , i also made the average which he wants me to do in a function but not in a function .. i need anyones help plzzzzzzzzzzzzzzzzzz
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int ID;
double D1;
double D2;
double D3;
double D4;
double D5;
double average;
double total=0;
ifstream inFile;
inFile.open("marks.txt");
if(!inFile)
{
cout << "Error" << endl;
return 1;
}
for (int i=1; i<=37; i++)
{
inFile >> ID;
inFile >> D1;
inFile >> D2;
inFile >> D3;
inFile >> D4;
inFile >> D5;
total=D1+D2+D3+D4+D5;
average=total/5;
cout << "ID: " << ID<< endl;
cout << "D1: " << D1 << endl;
cout << "D2: " << D2 << endl;
cout << "D3: " << D3 << endl;
cout << "D4: " << D4 << endl;
cout << "D5: " << D5 << endl;
cout << "The average grade for student " << ID << " is " << average << endl;
}
inFile.close();
return 0;
}
i did the program but i can't do the function that makes the average
This post has been edited by dandona: 01 May 2008 - 06:09 AM

New Topic/Question
Reply




MultiQuote




|