To write a simple C++ program. To use quotient-remainder arithmetic. To use format. To properly comment/document throughout a program.
iostream, iomanip
5 39 // 5 hours, 39 minutes
6 52 // 6 hours, 52 minutes
12 hours, 31 minutes // 12.52 hours
//project name "Time Measurements"
//reads time measurements from the keyboard in hours and minutes
//name: Whatchama call it.
//type of input: hours 1, hours 2, minutes 1, minutes 2
//type of output: time in hours and minutes and time as a real number
//brief description of algorithm: adds two data sets of hours and minutes
#include iostream
#include iomanip
using namespace std;
int main()
{
int hour1, hour2, minutes1, minutes2, total_hours, total_minutes;
float fraction_hours;
cout << fixed<> hour1;
cout << "Please type in 1st minute: ";
cin >> minutes1;
cout << "Please type in 2nd hour: ";
cin >> hour2;
cout << "Please type in 2nd minute: ";
cin >> minutes2;
total_minutes = hour1 * 60 + minutes1 + hour2 * 60 + minutes2;
total_hours = total_minutes / 60;
total_minutes = total_minutes % 60;
fraction_hours = total_hours + total_minutes / 60.0;
cout << total_hours << " hours " << total_minutes << " minutes \n";
cout << fraction_hours << " hours \n";
system("pause");
return 0;
}
Please type in 1st hour: 7
Please type in 1st minute: 43
Please type in 2nd hour: 12
Please type in 2nd minute: 36
20 hours 19 minutes
20.32 hours
Press any key to continue . . .
Woowiii - that was my 1st post! :)