Using CTime for calculations?

I have a program that calculates splits for running times (Track & Feild). Below is a copy of my function for calculating the quarter mile splits for a one mile run.

void CPaceCalculatorDlg::OnOneMile()
{
// TODO: Add your control notification handler code here
CString MinString;
CString SecString;
int min = 0;
int sec = 0;
int sec1,sec2,sec3,sec4,sec5,tsec1,min1,min2,tmin,tsec = 0;

m_edMin.GetWindowText(MinString);
m_edSec.GetWindowText(SecString);

min=atoi(MinString);
sec=atoi(SecString);

sec1 = min * 60;
sec2 = sec1 / 4;
sec3 = sec1 % 4;
min1 = sec2 / 60;
sec4 = sec2 % 60;
sec5 = sec / 4;
tsec1 = sec3 + sec4 + sec5;

if(tsec1 >= 60)
{
min2 = tsec1 / 60;
tmin = min1 + min2;
tsec = tsec1 % 60;
}
else
{
tmin = min1;
tsec = tsec1;
}

if((tsec <= 9) && (tsec >= 0))
{
MinString.Format("%d",tmin);
SecString.Format("%d",tsec);

MinString += ":0";
MinString += SecString;

m_edTime1.SetWindowText(MinString);
m_edDistance1.SetWindowText("Per Quarter Mile");
m_edTime3.SetWindowText("N/A");
m_edDistance3.SetWindowText("N/A");
}
else
{
MinString.Format("%d",tmin);
SecString.Format("%d",tsec);

MinString += ":";
MinString += SecString;

m_edTime1.SetWindowText(MinString);
m_edDistance1.SetWindowText("Per Quarter Mile");
m_edTime3.SetWindowText("N/A");
m_edDistance3.SetWindowText("N/A");
}

min = 0;
sec = 0;
sec1,sec2,sec3,sec4,sec5,tsec1,min1,min2,tmin,tsec = 0;

m_edMin.GetWindowText(MinString);
m_edSec.GetWindowText(SecString);

min=atoi(MinString);
sec=atoi(SecString);

sec1 = min * 60;
sec2 = sec1 / 2;
sec3 = sec1 % 2;
min1 = sec2 / 60;
sec4 = sec2 % 60;
sec5 = sec / 2;
tsec1 = sec3 + sec4 + sec5;

if(tsec1 >= 60)
{
min2 = tsec1 / 60;
tmin = min1 + min2;
tsec = tsec1 % 60;
}
else
{
tmin = min1;
tsec = tsec1;
}

if((tsec <= 9) && (tsec >= 0))
{
MinString.Format("%d",tmin);
SecString.Format("%d",tsec);

MinString += ":0";
MinString += SecString;

m_edTime2.SetWindowText(MinString);
m_edDistance2.SetWindowText("Per Half Mile");
m_edTime3.SetWindowText("N/A");
m_edDistance3.SetWindowText("N/A");
}
else
{
MinString.Format("%d",tmin);
SecString.Format("%d",tsec);

MinString += ":";
MinString += SecString;

m_edTime2.SetWindowText(MinString);
m_edDistance2.SetWindowText("Per Half Mile");
m_edTime3.SetWindowText("N/A");
m_edDistance3.SetWindowText("N/A");
}


}

How do I do the same thing using CTime, the function that I am using will only calculate to the nearest second and is only accurate within two seconds in some cases. The only documentation I have been able to find on CTime is for calculating days and how many hours between two times things like that. I want to be able to put in a time in minutes and seconds (5:25) and divide it by a number (4) and output the resulting time within two decimals. Please help.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories