Need Help

i have a code that is suppose to read from a file. but im trying to make the code output only the users first or last name from the file. if the file does not get first or last name, then the program will get a message. how do I write it?

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
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;

const int NUM_STUDENTS = 17;
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 Evaluation[NUM_STUDENTS];
    
    ifstream inStream;
    
    inStream.open("xxxxx");
    
    
    
    for (int index = 0; index < NUM_STUDENTS; index++)
	{
		cout << "Enter student's first name: ";
		cin >> Evaluation[index].firstName;
		
		cout << "Enter student's last name: ";
		cin >> Evaluation[index].lastName;
}


    

    
    system("pause");
    return 0;
}
    
Last edited on
What does the input file look like? Can you post an example?

What are you trying to do on lines 29-30?
im trying to make the program get the names from the file but I want to do it as first name "or" last name. if they enter any other name they would get an error messege saying it wasent in the file
the input file has a list of 17 students with 10 quizzes and 5 exams. you can put the numbers of your choice
Last edited on
Can you post a few lines from the file? I think that's what LB was asking to see.

Do you mean to read the content of the file into the array of student structs? Then let the user search by first or last name for a record?
yes thats what i meant. im trying to have the program the first or last name from a file.....then actually showing the user first names or last names '

for example

Johnn Matheew 78 45 65 12 78 78 100 12 58 64
Mary Jane 45 65 100 78 16 46 54 87 53 15

those can be in a file along with 15 other people
Last edited on
So you'd read all the names in the firstName, lastName and grades array(quizzes?) for each student into the struct array.

Are you going to ask the user if they want to search by first or last name? Then use the name they input with a search function that loops through the struct array looking for a record with that first or last name? Once the record is found, they can then update information for that student?

Maybe put that whole search process in a loop so the person can update another student if they want to?

Once records are updated, do you need to output the student data back into a file?
no i dont need to put it back in the file i just want the program to read the names from the file so that if they type a name thats not on the file, the program exits. i need that certain code so can i do a code for the average of the test and quizzes. how do i write it?
Last edited on
OK, but you'll read the data into the struct array first, not try to search directly on the file?

There's info on how to get data from files here.
http://www.cplusplus.com/doc/tutorial/files/
http://www.umich.edu/~eecs381/handouts/filestreams.pdf
Topic archived. No new replies allowed.