AVAILABLE: 5
Program:
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
int weeks(int w);
int days(int w);
int hours(int w);
//------------main function here----------------------------
void main() {
int w, i;
for (int i = 1; i > 0; i++) {
cout << "Convert time from hours to weeks, days, hours" << endl;
cout << "Press 1 to continue and 0 to exit: ";
cin >> i;
switch (i) {
case 1:
clrscr();
cout << "Enter time in hours: ";
cin >> w;
cout << endl << endl;
cout << "The converted time is: " << endl;
cout << weeks(w) << " weeks" << endl;
cout << days(w) << " days" << endl;
cout << hours(w) << " hours" << endl << endl;
break;
case 0:
exit(0);
break;
default:
cout << "Try again? Press 1, Exit? Press 0: ";
cin >> i;
break;
}
}
getch();
}
//-------------calculation functions are here-----------------
int weeks(int w) {
return (w / 168);
}
int days(int w) {
int a, h;
a = w % 168;
h = a / 24;
return (h);
}
int hours(int w) {
int a, h, b, j;
a = w % 168;
h = a / 24;
b = a % 24;
j = b / 1;
return (j);
}
Preview:
This program converts a given number of hours into weeks, days, and remaining hours. The user is prompted to enter hours and can repeat the process or exit the program.
End of code