time-in time out function

Please help me to make a time-in time-out fuction which extracts the no. of hours and minutes from a string entered by the user.


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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

string getEmpCode(string line){
    string code;

    for (unsigned i=0; i< line.length(); ++i) {

        if  (line.at(i) == ',')
            break;
        else
            code+= line.at(i);

    }

    return code;
}

string getEmpName(string line){
    string name="";
    int comma_ctr=0;
    int j=0;

    for (unsigned i=0; i< line.length(); ++i) {

        if  (line.at(i) == ','){
            comma_ctr++;
                i++;
        }

        if (comma_ctr==1){
            name+= line.at(i);
            j++;

        }else if (comma_ctr==2){

            break;
        }

    }

    return name;
}

string getLevel (string line){
  string level="";
  int comma_ctr=0;
    int j=0;

    for (unsigned i=0; i< line.length(); ++i) {

        if  (line.at(i) == ','){
            comma_ctr++;
                i++;
        }

        if (comma_ctr==2){
            level+= line.at(i);
            j++;

        }else if (comma_ctr==2){

            break;
        }

    }

    return level;
}

string getHour(string line){
    string hour;

    for (unsigned i=0; i< line.length(); ++i) {

        if  (line.at(i) == ',')
            break;
        else
            hour+= line.at(i);

    }

    return hour;
}


string getMinute (string line){
  string min="";
  int colon_ctr=0;
    int j=0;

    for (unsigned i=0; i< line.length(); ++i) {

        if  (line.at(i) == ':'){
            colon_ctr++;
                i++;
        }

        if (colon_ctr==1){
            min+= line.at(i);
            j++;

        }else if (colon_ctr==2){

            break;
        }

    }

    return min;
}



int main () {

  string line;
  ifstream myfile ("employee1.txt", ios::in);
  string delimiter=",";
  string ecode;
  bool found=false;
  string vcode, vname, vlevel;
  double dailyrate = 0.0, gross = 0.0;
  string time;
  string hour, min, ihour, fhour, t_hours;


  cout << "Enter Emp Code: ";
  getline(cin, ecode);

  if (myfile.is_open())
  {
    while ( myfile.good() )
    {
      getline (myfile,line);
        vcode= getEmpCode(line);
        if (ecode == vcode){
            found=true;

            vname= getEmpName(line);
            vlevel= getLevel(line);


            if (vlevel=="1")
            dailyrate= 200.00;
            else
            dailyrate= 250.00;

            cout << "Code: " + vcode + "\nName: " + vname + "\nLevel: " + vlevel + "\nDaily Rate: PHP " << dailyrate << "\n" ;
            cout << "\n";

            ofstream myfile2;
            myfile2.open ("record1.txt", ios::app);
            myfile2 << vcode << ", " << gross<<endl;
            myfile2.close();

            cout << "Enter Time-in for Monday(00:00 in 24 hour format): ";
            getline (cin,time);
            hour = getHour(line);
            min = getMinute(line);

            cout << "Enter Time-out for Monday(00:00 in 24 hour format): ";
            getline (cin,time);
            min = getMinute(line);
            getline (cin,time);
            cout << endl;

            cout << "Enter Time-in for Tuesday(00:00 in 24 hour format): ";
            getline (cin,time);
            cout << "Enter Time-out for Tuesday(00:00 in 24 hour format): ";
            getline (cin,time);
            cout << endl;


            cout << "Enter Time-in for Wednesday(00:00 in 24 hour format): ";
            getline (cin,time);
            cout << "Enter Time-out for Wednesday(00:00 in 24 hour format): ";
            getline (cin,time);
            cout << endl;


            cout << "Enter Time-in for Thursday(00:00 in 24 hour format): ";
            getline (cin,time);
            cout << "Enter Time-out for Thursday(00:00 in 24 hour format): ";
            getline (cin,time);
            cout << endl;



            cout << "Enter Time-in for Friday(00:00 in 24 hour format): ";
            getline (cin,time);
            cout << "Enter Time-out for Friday(00:00 in 24 hour format): ";
            getline (cin,time);
            cout << endl;



            break;

        }

    }
    if (!found){
        cout << "Employee don't exist!";
    }

    myfile.close();
  }

  else cout << "Unable to open file";

  return 
}


Im having hard time in finding the logic in converting string to integer.
Topic archived. No new replies allowed.