Reading file

What i actually want to do is get the program to read the file. from there i want the user to enter first "or" last name and then the program actually outputs the fule name and grade of the student for up to 15 scores " first 10 are quizzes worth up to 5%, and last 5 are exams worth up to 10%. Also if the user types a name thats not from the file...the program outputs an error messege. heres what i got thus far..

heres an example of how the .txt file look.

John doe 45 65 18 100 45 26 92 45 65 18 98 48 65 48 100
Mary jane 45 45 45 15 65 48 62 81 84 18 20 45 84 19 65

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

 #include <iostream>
 #include <iomanip>
 #include <fstream>
 #include <string>
 #include <cstdlib>
 using namespace std;
 
const int NUM_STUDENTS = 2;
 const int NUM_QUIZZES = 10;
 const int NUM_EXAMS = 5;
 
struct Student
 {
 string firstName;
 string lastName;
 int quizzes[NUM_QUIZZES];
 int exams[NUM_EXAMS];
 };
 
int main()
 {

 Student Cslculate[NUM_STUDENTS];
 int total = 0;
 int grade;
 
 
 if (grade >= 0 && grade <= 100)
 {
  if (grade >= 90)
   cout << "Letter Grade = A" << endl;
  else if (grade >= 80)
   cout << "Letter Grade = B" << endl;
  else if (grade >= 70)
   cout << "Letter Grade = C" << endl;
  else if (grade >= 60)
   cout << "Letter Grade = D" << endl;
  else
   cout << "Letter Grade = F" << endl;
 }


 ifstream inStream;
 ofstream ofStream;

 inStream.open ("C:\\Users\\xxxxx\\Desktop\\names.txt");
 ofStream.open ("C:\\Users\\xxxxx\\Desktop\\names.txt");
 
 
 if(!inStream)
 {
 cout << "Could not open input file. \n Exiting ..." << endl;
 system ("pause");
 exit(0);
 }
 
if(!ofStream)
 {
 cout << "Could not open output file. \n Exiting ..." << endl;
 system ("pause");
 exit(0);
 }
 for (int index = 0; index < NUM_STUDENTS; index++)
 {
 cout << "Please enter student name" << endl;
 inStream >> Cslculate[index].firstName;
 }

for (int index = 0; index < NUM_STUDENTS; index++)
	{
		inStream >> Cslculate[index].firstName >> Cslculate[index].lastName;
	
    
    	cout << left << setw(15) << Cslculate[index].firstName
			<< left << setw(15) << Cslculate[index].lastName
			<< endl;
	}

		




 inStream.close();
 ofStream.close();
 
 system("pause");
 return 0;
}
Topic archived. No new replies allowed.