I am making a simple program for my Dad's work. It is supposed to allow the user to add hardware(doors, locks, etc.) to the different schools. The user inputs the hardware in the function addhardware, and it is supposed to save it under showlist, so when you go to it you have a list of all the hardware. I only did it with one of the schools, to test it. But it's not working. I know I did something very wrong. It's like I know what to do, but i cant do it. Here is the code:
Code:#include <iostream> #include <windows.h> #include <fstream> using namespace std; void menu(); void schools(); void school1(); void school2(); void school3(); void hardware(); void addhardware(); void deletehardware(); void showlist(); int main() { menu(); cin.get(); cin.ignore(); return 0; } void menu() { int selection; system("CLS"); cout << "-------------------------------[ Hardware ]--------------------------------" << endl << endl; cout << "1. List of Schools" << endl; cout << "2. Exit" << endl; cin >> selection; switch (selection){ case 1: schools(); break; case 2: return; break; default: system("CLS"); cout << "Error: Incorrect Input!" << endl; Sleep(1000); menu(); break; } } void schools() { system("CLS"); int choice; cout << "------------------------------[ List of Schools ]-------------------------------" << endl << endl; cout << "1. High School" << endl; cout << "2. High School" << endl; cout << "3. Middle School" << endl; cin >> choice; switch (choice){ case 1: school1(); break; case 2: school2(); break; case 3: school3(); break; default: system("CLS"); cout << "Error: Incorrect Input!" << endl; Sleep(1000); schools(); break; } } void school1() { int selection; system("CLS"); cout << "1. Hardware" << endl; cout << "2. Go Back" << endl; cin >> selection; switch (selection){ case 1: hardware(); break; case 2: schools(); break; default: system("CLS"); cout << "Error: Incorrect Input!" << endl; Sleep(1000); school1(); break; } } void school2() { int selection; system("CLS"); cout << "1.Hardware" << endl; cout << "2.Go Back" << endl; } void school3() { system("CLS"); cout << "1.Hardware" << endl; cout << "2.Go Back" << endl; } void hardware() { int selection; system("CLS"); cout << "---------------------------------[ Hardware ]-----------------------------------" << endl << endl; cout << "1. Add Hardware" << endl; cout << "2. Delete Hardware" << endl; cout << "3. Show Hardware" << endl; cout << "4. Go Back" << endl; cin >> selection; switch (selection){ case 1: addhardware(); break; case 2: deletehardware(); break; case 3: showlist(); break; case 4: schools(); break; default: system("CLS"); cout << "Error: Incorrect Input!" << endl; Sleep(1000); hardware(); break; } } void addhardware() { system("CLS"); char addhardware[256]; cout << "--------------------------------[ Add Hardware ]--------------------------------" << endl << endl; cout << "Add Hardware:"; cin >> addhardware; ofstream file ("hardware.txt", ios::app); file << addhardware << endl; file.close(); ifstream fileb("hardware.txt"); fileb >> addhardware; cout << addhardware << endl; ifstream a_file ( "hardware.txt"); if ( !file.is_open()){ } else { } } void deletehardware() { system("CLS"); cout << "------------------------------[ Delete Hardware ]-------------------------------" << endl << endl; } void showlist() { system("CLS"); cout << "------------------------------[ Hardware List ]---------------------------------" << endl << endl; }