How do you join hours and minutes

For example:

cout << "Please enter the starting time in Hour format" << endl;
cin >> hour;
cout << "Please enter the starting time in minute format" << endl;
cin >> minute;

How do I join the two together like one world.
What do you mean by "join together like one world"?

Also, what are the types of hour and minute?

-Albatross
OMG I missing some wold. Like this,

cout << "Please enter the starting time in Hour format" << endl;
cin >> hour;
cout << "Please enter the starting time in minute format" << endl;
cin >> minute;

Let says the user enter 5 for the hour and 2 minute:

I will have other "cout" says: you have talk for 5 hour and 2 minute.

Question is: how do I make 5 hour and 2 minute into one variable?

since hour and min are variables!

like

total= hour.minute?

I want for outcome is 5.2 or something....



I also like total= hour << minute; didn't work.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
struct Time
{
    int hour , minute;
};

int main()
{
    Time t1 = { 5 , 2 };

    std::cout << t1.hour << " hour and " << t1.minute << " minute." << std::endl;
}


Something like this? Or are you talking about string format?
-_-
Last edited on
I think he's putting hours and minutes into decimal hours:
1
2
3
4
5
6
cout << "Please enter the starting time in Hour format" << endl;
cin >> hour;
cout << "Please enter the starting time in minute format" << endl;
cin >> minute;

double hours = hour + (minute / 60.);
The Xcode say Redefinition of 'hours':

on the top I put double hours;
Since minutes aren't in base 10, you have to add the minute fraction (minutes/60) to the hour, the same way you would do with like, 1 foot 7 inches. 1'7" == 1+(7/12) feet.
so 1m55s == 1 + (55/60) minutes.
 
double total = hour + (minute / 60);
Thank you guys it work
Topic archived. No new replies allowed.