Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

what is wrong with my code?? #include <iostream> #include <fstream> #include <st

ID: 3762147 • Letter: W

Question

what is wrong with my code??

#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();
}

Explanation / Answer

code is working fine but you have to change the compiler.

use c++ 11 or later for that

I have submitted online compiler link and compiler result

https://ideone.com/ugtxj2