C++ how to take user input of time and seperate it into hours and minutes?
I need to take a users input such as 10:35 and put it into a variable of hours and minutes. How can I do this using the colon as the separate for the two? This is how the assignment requires it be entered.
Example of what I am doing.
int main()
{
char again = 'y';
int userHours = 0;
int userMinutes = 0;
while (again == 'y')
{
cout << "Enter a time in 24-hour notation: ";
cin >> userHours >> ":" >> userMinutes;
}
return 0;
}
Actually I already solved it thanks to the people on stackoverflow. Just need a variable for the colon, so I just added the lines.
char colon;
cin >> userHours >> colon >> userMinutes;