Names

Dec 10, 2014 at 10:19pm
Im trying to get my program to output the name from a file. The user should enter first name "or" last name. and if the user does not type the name from the input file. the get an error message. How do you do it

#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: ";
inStream >> Evaluation[index].firstName;

cout << "Enter student's last name: ";
inStream >> Evaluation[index].lastName;

if(!inStream)
{
cout << "The name you have entered does not appear on the list" << endl;
}
}
system("pause");
return 0;
}


Last edited on Dec 10, 2014 at 10:19pm
Dec 10, 2014 at 10:24pm
Dec 11, 2014 at 12:42am
can you please help? im still a beginner
Dec 11, 2014 at 1:48am
I edited it.
Code:
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
#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;
string firstName;
string lastName;
int quizzes[NUM_QUIZZES];
int exams[NUM_EXAMS];

int main()
{
ifstream inStream;
ofstream outStream;
inStream.open("Names.dat");
int x=1;
while(x=1){
if(!inStream.good()){
cout<<"File not open!\nRetrying";
system("pause");
inStream.open("Names.dat");
}else{break;}}
for (int index = 0; index < NUM_STUDENTS; index++)
{
cout << "Enter student's first name: ";
cin>>firstName;
getline(inStream,firstName,' ');
cout << "Enter student's last name: ";
cin>>lastName;
inStream>>lastName;

if(!inStream)
{cout << "The name you have entered does not appear on the list" << endl;}}
system("pause");
return 0;
}
Dec 11, 2014 at 1:53am
its an array of structure code
Topic archived. No new replies allowed.