How will I add the existing content of the text file to the newly inputed date(hoursworked & minsWorked) to compute the total number of hours works please help me I'm just a beginner in using Visual basic C++. I dont know wht to do please help me guys.
I hope you can help me please this is in rush
#include <iostream>
#include <fstream>
#include<string>
#include <cstdlib>
using namespace std;
bool parseTime(char* _timeStr, int& _hour, int& _min)
{
// Make sure a pointer was passed in
if (NULL == _timeStr)
return false;
// Hours starts at the string passed in, minutes we figure out in a second
char* hourStr = _timeStr;
char* minStr = NULL;
// Loop through the string looking for the : character
char* curChar = _timeStr;
while (*curChar)
{
if (':' == *curChar)
{
// Found our minutes string. NULL terminate the hour string and set the minute string.
*curChar = '\0';
minStr = curChar + 1;
break;
}
++curChar;
}
// If no minute string was found, error
if (NULL == minStr)
return false;
// Convert the strings to integers and store them
_hour = atoi(hourStr);
_min = atoi(minStr);
// Restore the : character (could also use the "curChar" variable for this, but this way is more fun)
*(minStr - 1) = ':';
// Test for invalid values
if (_hour < 0 || _hour > 23)
return false;
if (_min < 0 || _min > 59)
return false;
// Theoretical success!
return true;
}
int main ()
{
char time1[80];
char time2[80];
std::ofstream outfile;
string line;
string name;
int totaltimeused;
ofstream myfile;
myfile<<totaltimeused;
myfile.close();
cout<<"Enter your name :";
cin>>name;
if(name=="a")
{
ifstream myfiles ("herald.txt");
if (myfiles.is_open())
{
while ( getline (myfiles,line) )
{
cout << line << '\n';
}
myfiles.close();
}else{
cout << "Unable to open file"; }
if (!parseTime(time1, hour1, min1))
{
cout << "Error parsing time 1: " << time1 << ". Invalid time format.\n";
return(0);
}
if (!parseTime(time2, hour2, min2))
{
cout << "Error parsing time 2: " << time2 << ". Invalid time format.\n";
return(0);
}
// Hours worked and minutes worked
int hoursWorked = hour2 - hour1;
int minsWorked = min2 - min1;
// It is possible that a full hour was not worked, meaning the minutes would be negative.
if (minsWorked < 0)
{
// If that is the case, deduct one hour and add 60 minutes. Since minutes is negative, this
// yields the actual minutes worked (IE, -4 becomes 56).
--hoursWorked;
minsWorked += 60;
}