The prob is that i am initializing the variable as "N/A" and saving it to a text file. it is declared as a string. look at the code:
Expand|Select|Wrap|Line Numbers
- #include <iostream.h>
- #include <fstream>
- #include <cstdlib>
- #include <string>
- using namespace std;
- //Account data structure
- struct account
- {
- string user;
- string enter_password;
- };
- //Dining Data Structure
- struct Dining
- {
- account username;
- string name; // the variable that i'm using to store the name
- string time;
- int persons;
- char status;
- };
- // Array declaration
- Dining seats[8][4];
- char reserve[] = "C:\\Seat Reserving.txt";
- void show();
- void username_entry();
- /*
- password user_pass[5];
- char username[] = "C:\\Username Password Storage";
- */
- void initialise();
- void clear();
- //Seats reserving
- void to_reserve();
- int input();
- void showed_up();
- int main()
- {
- ifstream check_b4_start;
- check_b4_start.open(reserve);
- if(check_b4_start.fail())
- {
- cout<<"The file failed to open"<<endl;
- cout<<"No file was found"<<endl;
- cout<<"File created"<<endl;
- initialise();
- system("PAUSE");
- system ("cls");
- }
- to_reserve();
- //show();
- //username_entry();
- system("PAUSE");
- return 0;
- }
- void initialise()
- {
- ofstream ini; //varible declared for input
- ini.open(reserve);
- if (ini.fail())
- {
- cout<<"The file failed to open"<<endl;
- system ("PAUSE");
- exit(1);
- }
- else
- {
- // cout<<"The file opened sucessfully"<<endl;
- for (int n = 0; n < 8; n++)
- {
- for (int x = 0; x < 4; x++)
- {
- seats[n][x].username.user = "N/A";
- seats[n][x].username.enter_password = "N/A";
- seats[n][x].name = "N/A"; // initialization of the variable to text file
- seats[n][x].time = "N/A";
- seats[n][x].persons = 0;
- seats[n][x].status = 'E';
- ini<<seats[n][x].username.user<<endl;
- ini<<seats[n][x].username.enter_password<<endl;
- ini<<seats[n][x].name<<endl;
- ini<<seats[n][x].time<<endl;
- ini<<seats[n][x].persons<<endl;
- ini<<seats[n][x].status<<endl;
- ini<<endl;
- }
- }
- ini.close();
- if (ini.fail())
- {
- cout<<"The file failed to close"<<endl;
- system ("PAUSE");
- exit(1);
- }
- }
- }
- void show()
- {
- ifstream showing;
- showing.open(reserve);
- if (showing.fail())
- {
- cout<<"The file failed to open"<<endl;
- system ("PAUSE");
- exit(1);
- }
- else
- {
- cout<<"The file open sucessfully"<<endl;
- cout<<"\nBelow shows which seats are free"<<endl;
- cout<<"\n 0 1 0 1 2 3 2 3"<<endl;
- for (int n = 0; n < 8; n++)
- {
- for ( int x = 0; x < 4; x++)
- {
- showing>>seats[n][x].username.user;
- showing>>seats[n][x].username.enter_password;
- showing>>seats[n][x].name;
- showing>>seats[n][x].time;
- showing>>seats[n][x].persons;
- showing>>seats[n][x].status;
- cout<<seats[n][x].status;
- if (x == 0)
- {
- cout<<n;
- }
- if ((n < 2) && (x == 0))
- {
- cout<<" ";
- }
- if ((n > 1) && (n < 6) && (x == 2))
- {
- cout<<" ";
- }
- if ((n > 5) && (x == 0))
- {
- cout<<" ";
- }
- cout<<seats[n][x].status;
- }
- cout<<endl;
- }
- }
- }
- void username_entry()
- {
- char user_entered[10];
- string password;
- ifstream entry;
- bool enter_correct = false;
- bool name_bad = false;
- bool pass_bad = false;
- while (enter_correct == false)
- {
- cout<<"Please enter username- ";
- cin.getline(user_entered,10);
- cout<<endl;
- cout<<"Enter password- ";
- cin>>password;
- cout<<endl;
- entry.open(reserve);
- if(entry.fail())
- {
- cout<<"The file failed to open"<<endl;
- system ("PAUSE");
- exit(1);
- }
- else
- {
- for (int n = 0; n < 8; n++)
- {
- for ( int x = 0; x < 4; x++)
- {
- entry>>seats[n][x].username.user;
- entry>>seats[n][x].username.enter_password;
- entry>>seats[n][x].name;
- entry>>seats[n][x].time;
- entry>>seats[n][x].persons;
- entry>>seats[n][x].status;
- if ((seats[n][x].username.user == user_entered) && (seats[n][x].username.enter_password == password))
- {
- enter_correct = true;
- }
- if ((seats[n][x].username.user == user_entered) && (seats[n][x].username.enter_password != password))
- {
- pass_bad = true;
- }
- if ((seats[n][x].username.user != user_entered) && (seats[n][x].username.enter_password != password))
- {
- pass_bad = true;
- name_bad = true;
- }
- if ((seats[n][x].username.user != user_entered) && (seats[n][x].username.enter_password == password))
- {
- name_bad = true;
- }
- }
- }
- if ((name_bad == true) && (pass_bad == false))
- {
- cout<<"There is no such person found"<<endl;
- }
- if ((pass_bad == true) && (pass_bad == false))
- {
- cout<<"You entered the password incorrectly"<<endl;
- }
- if ((pass_bad == true) && (name_bad == true))
- {
- cout<<"That person and password is not found"<<endl;
- }
- if (enter_correct == true)
- {
- cout<<"You have entered the correct password or username"<<endl;
- }
- entry.close();
- if (entry.fail())
- {
- cout<<"The file failed to close"<<endl;
- system ("PAUSE");
- exit(1);
- }
- }
- }
- system ("cls");
- cout<<"\n WELCOME"<<endl;
- }
- void to_reserve()
- {
- show();
- int mini_ch;
- bool exit = false;
- int ex_ch = input();
- cout<<"1- To reserve seats"<<endl;
- cout<<"2- exit to menu"<<endl;
- cin>>mini_ch;
- while (exit == false)
- {
- if(mini_ch == 1)
- {
- input();
- show();
- }
- if (mini_ch == 2)
- {
- exit = true;
- }
- if (ex_ch == 0)
- {
- exit = true;
- }
- else
- {
- cout<<"Invalid Entry"<<endl;
- }
- }
- }
- int input()
- {
- ofstream inp;
- int row, coloumn;
- char decision;
- int exit_ch = 2;
- while (exit_ch == 2)
- {
- cout<<"Please enter the row and column for the seat you want- "<<endl;
- cin>>row;
- cout<<endl;
- cin>>coloumn;
- cout<<"\nWho is reserving this seat";
- cin.getline(seats[row][coloumn].name); //trying to use getline() to read the name in
- cout<<"\nWhat time would you like";
- cin>>seats[row][coloumn].time;
- cout<<"\nHowmany persons would be joining you- ";
- cin>>seats[row][coloumn].persons;
- cout<<endl;
- seats[row][coloumn].status = 'R';
- cout<<"Do you want to save this configuration (y/n)- ";
- cin>>decision;
- cout<<endl;
- inp.open(reserve);
- if (inp.fail())
- {
- cout<<"The file failed to open"<<endl;
- system ("PAUSE");
- exit(1);
- }
- else
- {
- if (decision == 'y')
- {
- //inp<<seats[row][coloumn].name;
- inp<<seats[row][coloumn].time;
- inp<<seats[row][coloumn].persons;
- inp<<seats[row][coloumn].status;
- exit_ch = 0;
- }
- if (decision == 'n')
- {
- cout<<"1- to re-enter the data"<<endl;
- cout<<"2- to exit to menu"<<endl;
- cin>>exit_ch;
- }
- inp.close();
- if (inp.fail())
- {
- cout<<"The file failed to close"<<endl;
- system ("PAUSE");
- exit(1);
- }
- }
- }
- return exit_ch;
- }