
Help using time.h to calculate running time...
Try this out. You may find it helpful for your program:
___________________
I was using Borland 4.51, so you may need to edit this
some depending on your compiler!
// You don't need all of these header files, I was just cutting and pasting
this for you.
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstring.h>
#include <dos.h>
#include <conio.h>
#include <graphics.h>
#include <io.h>
#include <math.h>
#include <fcntl.h>
#include <process.h>
#include <alloc.h>
#include <alloc.h>
long main(void)
{
. // Removed code was here.
.
.
.
int oldhour; int oldminute;
int newhour; int newminute;
string oldampm; string pmhours = "PM"; string amhours = "AM";
string newampm;
struct time t; /* to display the time */
. // Removed code was here.
.
.
.
gettime(&t);
if (t.ti_hour >= 13)
{
oldhour = t.ti_hour - 12;
oldminute = t.ti_min;
oldampm = pmhours;
}
else
{
oldhour = t.ti_hour;
oldminute = t.ti_min;
if (t.ti_hour >= 12)
{
oldampm = pmhours;
}
else
{
oldampm = amhours;
}
}
. // Removed code was here.
.
.
.
cout << "\n\n START TIME: " << oldhour << ":" << oldminute << oldampm <<
endl;
gettime(&t);
if (t.ti_hour >= 13)
{
newhour = t.ti_hour - 12;
newminute = t.ti_min;
cout << "COMPLETION TIME: " << newhour << ":" <<
newminute << "PM" << endl;
}
else
{
newhour = t.ti_hour;
newminute = t.ti_min;
cout << "COMPLETION TIME: " << newhour << ":" <<
newminute;
if (t.ti_hour >= 12)
{
cout << "PM" << endl;
newampm = "PM";
}
else
{
cout << "AM" << endl;
newampm = "PM";
}
Quote:
}
. // Removed code was here.
.
.
.
return 0;
Quote:
}