I was asked to enter an hour and a minute on the same line. But when I enter the hour, it automatically goes to a new line, and I'm only able to enter the minute on the next line. However, I want to enter the hour and minute on the same line with a colon between them. It should look like this
Time: 4:54
But my code produces this:
Time: 454
cout << "\n\tTime: ";
cin >> timeHours;
cin.get();
cin >> timeMinutes;
You can do that as the following :
cin >> timeHours >> timeMinutes;
according to the documentation :
the user is expected to introduce two values, one for variable a, and another for variable b. Any kind of space is used to separate two consecutive input operations; this may either be a space, a tab, or a new-line character.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With