What is wrong with my program?

everything was going smooth then i don't know what happened the program stopped working here's the code in c++ im trying to write a student database, also im having trouble putting in a code to sort the records out in ascending order im pretty sure i have to enter a array but im having truible knowing where to put it..if anyone can help plsss.

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

void input();
void search();
void edit();
void displayAll();


int main()
{
system("cls");
system("title Omar Hamad database program");
system("color 0f");

cout << "Please enter choice" << endl;
cout << "1.Input new student" << endl;
cout << "2.Search for a student" << endl;
cout << "3.Edit existing students information" << endl;
cout << "4.Display all students" << endl;
cout << "5.Exit" << endl;

int choice;
cin >> choice;

switch (choice) {
case 1:
input();
break;
case 2:
search();
break;
case 3:
edit();
break;
case 4:
displayAll();
break;
}
}
void input()
{
system("cls");
string fname;
string mname;
string lname;
string filename;
string address;
string gender;
string hobbies;
string eaddress;
double phoneNumber;
double gpa;
double salary;
int empId;
int age;

cout << "Input students first name:";
cin >> fname;
cout << "Input students middle name:";
cin >> mname;
cout << "Input students last name:";
cin >> lname;
cout << "Input student age:";
cin >> age;
cout << "Input student salary:";
cin >> salary;
cout << "Input studnet Id number:";
cin >> empId;
cout << "Input students phone number:";
cin >> phoneNumber;
cout << "Input students address:";
cin >> address;
cout << "Input student gender:";
cin >> gender;
cout << "Input students GPA:";
cin >> gpa;
cout << "Input students hobbies:";
cin >> hobbies;
cout << "Input students email address:";
cin >> eaddress;
string empId2 = to_string(empId);
empId2.append(".txt");

ofstream newemployee(empId2);
newemployee << fname << ' ' << mname << ' ' << lname << ' ' << empId << ' ' << salary << ' ' << age << ' ' << phoneNumber << ' ' << address << ' ' << gender << ' ' << gpa << ' ' << hobbies << ' ' << eaddress << endl;
newemployee.close();
}
void search()
{
system("cls");
string fname;
string mname;
string lname;
string filename;
string address;
string gender;
string hobbies;
string eaddress;
double phoneNumber;
double gpa;
double salary;
int empId;
int thrw;
int age;
cout << "Enter student ID Number:";
cin >> empId;
string empId2 = to_string(empId);
empId2.append(".txt");

ifstream employee(empId2);
while (employee >> fname >> mname >> lname >> thrw >> salary >> age >> gender >> hobbies >> eaddress >> phoneNumber >> gpa) {
int mnameLength = mname.size();
int lnameLength = lname.size();
int fnameLength = fname.size();
int lengthtotal = fnameLength + lnameLength + mnameLength;

string answer;
cout << "Is this the correct student?[Y/N]" << endl;
cout << fname << ' ' << mname << ' ' << lname << endl;
cin >> answer;

if (answer == "Y") {
system("cls");
cout << "Name";
for (int y = 1; y, lengthtotal; y++) {
cout << " ";
}
cout << "Age";
for (int z = 1; z < 2; z++) {
cout << " ";
}
cout << "Salary";
cout << "ID Number" << endl;
for (int x = 1; x < lengthtotal + 20; x++) {
cout << "-";
}
cout << ' ' << endl;
cout << fname << ' ' << mname << ' ' << lname << ' ' << age << "$" << salary << ' ' << empId << endl;
}


}

main();
}
void edit()
{
system("cls");
string fname;
string mname;
string lname;
string address;
string gender;
string hobbies;
string eaddress;
string newaddress;
string newgender;
string newhobbies;
string neweaddress;
string newfname;
string newmname;
string newlname;
string decision;
int empId;
int age;
int newage;
int thrw;
double phoneNumber;
double newphoneNumber;
double gpa;
double newgpa;
double salary;
double newsalary;
cout << "Enter the new student ID whom you want to edit:";
cin >> empId;
string empId2 = to_string(empId);
empId2.append(".txt");

ifstream employee(empId2);

while (employee >> fname >> mname >> lname >> thrw >> salary >> age >> gender >> hobbies >> eaddress >> phoneNumber >> gpa) {
if (decision == "Y") {
system("cls");
cout << "Current Information:" << endl;
int mnameLength = mname.size();
int lnameLength = lname.size();
int fnameLength = fname.size();
int lengthTotal = fnameLength + lnameLength + mnameLength;

cout << "Name";
for (int y = 1; y < lengthTotal; y++) {
cout << " ";
}
cout << "Age";
for (int z = 1; z < 2; z++) {
cout << " ";
}
cout << "Salary";
cout << "ID Number" << endl;
for (int x = 1; x < lengthTotal + 20; x++) {
cout << "-";
}
cout << ' ' << endl;
cout << fname << ' ' << mname << ' ' << lname << ' ' << age << ' ' << "$" << salary << ' ' << gender << ' ' << hobbies << ' ' << eaddress << ' ' << phoneNumber << ' ' << empId << endl;

cout << "Enter new student first name:";
cin >> newfname;
cout << "Enter new student middle name:";
cin >> newmname;
cout << "Enter new studnet last name:";
cin >> newlname;
cout << "Enter new student age:";
cin >> newage;
cout << "Enter new student salary:";

}
if (decision == "N") {
main();
}
employee.close();
ofstream employee2(empId2);
employee2 << newfname << ' ' << newmname << ' ' << newlname << ' ' << empId << ' ' << newsalary << ' ' << newage << ' ' << newgender << ' ' << newhobbies << ' ' << neweaddress << ' ' << newphoneNumber << ' ' << newgender << endl;
employee2.close();
}
main();

}
void displayAll()
{
system("cls");
string fname;
string mname;
string lname;
string address;
string gender;
string hobbies;
string eaddress;
double phoneNumber;
double gpa;
int age;
double salary;
int empId;

cout << "This is the entire student database" << endl;
cout << "-----------------------" << endl;
ifstream dir("directory.txt");
while (dir >> fname >> mname >> lname >> age >> empId >> salary >> gender >> hobbies >> eaddress >> phoneNumber) {
cout << fname << ' ' << mname << ' ' << lname << ' ' << age << ' ' << salary << empId << endl;
}
system("pause");
main();
}







Please use code tags. It is easier to read and to help with.
http://www.cplusplus.com/forum/articles/42672/
closed account (48T7M4Gy)
Except for a couple of compiler errors I picked up using VS2015 this code actually runs which I thought was amazing. 'Amazing' because we don't see statements like main(); instead of return very often. Besides that it runs without compiler errors using the cpp shell.

A simple array will do the job but you will need lots of individual arrays to capture each attribute/property of a student. A better solution to that would be to go one step further with your program and create a Student struct or Student class ( even better ) and have an array of students. STL vectors or maps would be even better.

Sorting is explained in detail in http://www.cplusplus.com/articles/NhA0RXSz/

Fix up your compiler error problems unless you want to use the online shell and you should be back in business in no time. :)
Topic archived. No new replies allowed.