okay so I'm writing a program that defines a time instead of HH:MM it is formated as HH.MM. User of the program inputs a time in this format (IE: 1.30 for 1:30)
I need to give an error output if user inputs anything over 59 in the MM position. HH.MM is defined as a floating-point variable "num" How do I define the decimal/fractional part of this variable so I can output an error if MM > 59
ah, figured it out. wasn't too sure what the static_cast<int> command is for. Just used it to get the integer of "num" then subtract it from "num" to get the fractional part of "num"
static_cast<int> is used to convert to integer without compilers throwing loss of conversion warnings. (well it is in java so I assume it is in C++, so I hope I'm not misleading you)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
using std::cout;
int main()
{
int A=0;
double B=6432.964;
A = static_cast<int> (B);
cout << A;
return 0;
}
yeah I got a bit of an inaccuracy defining it as a floating point variable, defined it as a double and voila.
Thanks for the help and the reading material.