C++ Primer Plus Chapter 2 Exercise 6

c plus plusChapter 2 ends with a  problem that requires you to store some integer values in a function and return them in the typical hour:minute format. Here is my solution:

6. Write a program that asks the user to enter an hour value and a minute value. The
main() function should then pass these two values to a type void function that displays
the two values in the format shown in the following sample run:
Enter the number of hours: 9
Enter the number of minutes: 28
Time: 9:28

 #include <iostream>

using namespace std;

void time(int, int);
int hours;
int minutes;

int main()
cout << "Enter a number of hours: ";
cin >> hours;

cout << "Enter number of minutes: ";
cin >> minutes;

time(hours, minutes);

return 0;

void time(int hours, int minutes)
cout << "Time: " << hours << ":" <<  minutes << endl;