Getting back into C++

I used to know more when i was younger but slacked off for certain reasons.

Right now I'm trying to relearn the basics. I figure a good way is to write a program. Here's code I have so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <cstdlib>
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main(int argc, char *argv[])
{

    int iOption;
    int iEmployeeID;
    char input;
    char cnt = 'y';
    
    struct Employee_data {
            string sName;
            int iID;
            float fSalary;
            string sDOB;
            string sDOH;
            
            
            } Employee1, Employee2, Employee3, Employee4, Employee5;
     
    cout << "Welcome to employee database. Please choose from following options." << endl
         << endl;
         
    cout << "1. List employee information." << endl
         << "2. Add employee information." << endl
         << "3. Delete employee information." << endl
         << "4. Edit employee information." << endl
         << "5. Save changes and exit." << endl
         << endl << "Selection: ";
         
         
    cin >> iOption;
    
    switch(iOption) {
           case 1: 
                {
                    
                      cout << endl <<"You chose option 1, please enter ID# of Employee you would like to review." << endl
                      << "Selection: ";
                      cin >> iEmployeeID;
                      
                  break;    
                }
           case 2: 
                {
                      cout << "You chose option 2, please enter ID# of Employee you would like to add." << endl
                      << endl << "ID#: ";
                      cin >> Employee1.iID;
                      
                      cout << "Now enter name of employee" << endl << "Name: ";
                      cin >> Employee1.sName;
                      
                      cout << "Now enter employee salary in decimal form" << endl 
                      << endl << "Salary: ";
                      cin >> Employee1.fSalary;
                      
                      cout << "Now enter employee date of hire." << endl
                      << endl << "DOH: ";
                      cin >> Employee1.sDOH;
                      
                      cout << "Now enter employee date of birth." << endl
                      << endl << "DOB: ";
                      cin >> Employee1.sDOB;
                      
                      
                      cout << endl << endl 
                           << "You have entered..." <<endl<< endl
                           << "ID#: " << Employee1.iID << endl
                           << "Name: " << Employee1.sName << endl
                           << "Salary: " << Employee1.fSalary << endl
                           << "DOH: " << Employee1.sDOH << endl
                           << "DOB: " << Employee1.sDOB << endl;
                      
                      cout << "Return to main menu? y/n: ";
                      cin >> input;
                           
                  break;    
                }
           case 3: 
                {
                      cout << "You chose option 3, please enter ID# of Employee you would like to delete." << endl
                      << endl << "ID#: ";
                      cin >> iEmployeeID;
                  break;    
                }
           case 4: 
                {
                      cout << "You chose option 4, please enter ID# of Employee you would like to edit." << endl
                      << endl << "ID#: ";
                      cin >> iEmployeeID;
                  break;    
                }
                
}
    // 1 list employee information. employee information includes. name, date of hire, date of birth
    // salary, employee id number.
    
    // delete employee information.
    
    // add employee information, take in name, date of hire, date of birth, salary, employee id number
    // store for later retrieval 
    
    system("PAUSE");
    return EXIT_SUCCESS;

    
}


So as you can see I'm trying to make a simple database that just stores information for employees. I want to be able to save it all to a file for later retrieval, be able to delete, add, edit, etc. Also repeat the menu. It's working in so far as I can store the info, but I haven't read anything on saving info and I can't seem to get it to repeat the menu. If I wrap it all up in something like while (char!='n') it compiles but nothing happens. Any ideas are appreciated, not asking anyone to write it for me but if you know what I need to learn to use or what I need to read to complete it it's much appreciated because I know no one personally who can help me.

Thanks!
You need some kind of loop. You break out of the loop when the user chooses not to continue.

Although making your declarations as local as possible is the best way, that Employee struct should be at global scope. Then you can use a collection of these structs rather than declaring 5 separate employee variables.

You need to take a look at the use of ifstream and ofstream. And also take a look at the idea of streaming. Once you've done that, you'll see that you can add streaming operators to your Employee thing which you use to stream employees to and from the file.
Here are some links that will help you
http://www.cplusplus.com/doc/tutorial/files/ (for file output and input)
http://www.cplusplus.com/doc/tutorial/control/ (the do-while loop)
http://www.cplusplus.com/reference/stl/vector/vector/ (to easily manage data)
Topic archived. No new replies allowed.