S
Schizoid Man
I have the following code snippet where I am validating time in minutes
and hours entered in as a double variable.
If I enter the value 10.59, the value printed out is 10:58. For this
input, the correct value is being passed to 'temp', so I just can't
figure out why fmod() is misbehaving.
Any ideas?
double InputTime, temp;
int Hours, Minutes;
cout << "Enter the start time: ";
cin >> InputTime;
Hours = static_cast<int>(InputTime);
temp = InputTime - Hours;
temp = temp * 100.0;
Minutes = fmod(temp, 100);
cout << "Time is " << Hours << ":" << Minutes;
and hours entered in as a double variable.
If I enter the value 10.59, the value printed out is 10:58. For this
input, the correct value is being passed to 'temp', so I just can't
figure out why fmod() is misbehaving.
Any ideas?
double InputTime, temp;
int Hours, Minutes;
cout << "Enter the start time: ";
cin >> InputTime;
Hours = static_cast<int>(InputTime);
temp = InputTime - Hours;
temp = temp * 100.0;
Minutes = fmod(temp, 100);
cout << "Time is " << Hours << ":" << Minutes;