Why does my code not run properly? As soon as it gets to the if else statement it takes one input from the user and then exits before I can enter anything else. I am not sure if it is due to the function not returning properly but I would really appreciate some help. Thanks.
#include <iostream>
#include <fstream>
using namespace std;
void studentenrollment (char answer);
int main()
{
char answer; //declaring variables for main
cout << "Welcome to Luton Sixth Form" << endl; //greeting the user
cout << "Please State if you are enrolled or not at the sixth form: Y/N" << endl;//giving user options
cin >> answer;//taking options from user
studentenrollment(answer); //calling student enrollment function
return 0;
}
void studentenrollment (char answer)
{
unsigned char name;
int dob;
if (answer=='Y'||answer=='y')
{
cout << "Welcome to higher education" << endl;
cout << "Please state your name" << endl;
cin >> name;
ofstream myfile;
myfile.open("StudentAccess.txt");
myfile << name << endl;
myfile.close();
cout << "Your name is now saved, you have access to the gateway" << endl;
}
else if(answer=='N'||answer=='n')
{
cout << "Please state your name" << endl;
cin >> name;
cout << "Please enter your date of birth" << endl;
cin >> dob;
ofstream myfile;
myfile.open("StudentEnrollment.txt");
myfile << name << dob << endl;
myfile.close();
cout << "You will now go through enrollment" << endl;
}
// return 0;
}