IN C++ Now write a program to convert minutes to time (separate hours/minutes).
ID: 3685993 • Letter: I
Question
IN C++
Now write a program to convert minutes to time (separate hours/minutes). Include a user-defined void function named minutesToTime that takes an integer number of minutes and converts it to two separate integer values that represent the equivalent number of hours and minutes. You must use reference parameters for the hours and minutes. Before proceeding further, discuss with a neighbor or TA why this function uses reference parameters. void minutesToTime(int minute_value, int& hours, int& mins) Your main program needs to do the following: Prompt the user to input an integer number of minutes from the console. Call minutesToTime to compute the equivalent number of hours and minutes. Display the result on the terminal display using a 'colon' character to separate hours and minutes. Moreover, if the number of minutes is less than 10, print it out with a leading zero Include a loop that will continue this process as long as the user wishes.Explanation / Answer
Program:
#include<iostream>
#include<iomanip>//used by setw and setfill
using namespace std;
//function
void minutesToTime(int minute_value,int& hours,int& mins)
{
//calculate mins and hours
mins=minute_value%60;
hours=minute_value/60;
}
int main()
{
char choice;
int hours;
int mins;
int minute_value;
while(1)
{
cout<<"Enter number of minutes : ";
cin>>minute_value;
minutesToTime(minute_value,hours,mins);
//setfill and setw are used to print with leading zeros
cout<<"Hours:minutes is "<<hours<<":"<<setfill('0') << setw(2)<<mins<<endl;
cout<<"Continue? (y/n) : ";
cin>>choice;
//if choice is y continue loop otherwise break
if(choice=='y')
continue;
else
break;
}
return 0;
}
Sample output:
Enter number of minutes : 56
Hours:minutes is 0:56
Continue? (y/n) : y
Enter number of minutes : 78
Hours:minutes is 1:18
Continue? (y/n) : y
Enter number of minutes : 61
Hours:minutes is 1:01
Continue? (y/n) : n