1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <stdio.h>
using namespace std;
int main (void)
{
int totalHrs = 0;
int totalMins = 0;
int totalSecs = 0;
int hrs;
while (cin >> hrs)
{
int min, sec;
string title;
cin >> min >> sec >> ws;
getline (cin, title);
int add = (totalHrs, totalMins, totalSecs);
printf ("%d x %d = %d\n", totalHrs, totalMins, totalSecs, add);
int normalize(int sec, int min, int hrs);
int twoDigits(char sec, char min, char hrs);
int printTime(int totalHrs, int totalMins, int totalSecs);
}
return 0;
}
// Normalize the time and print the song
int normalize (int sec, int min, int hrs)
{
sec = sec % 60;
min = sec / 60;
hrs = min / 60;
}
// Add this time to the sum.
// Keep the sum normalized
//(useful for debugging purposes)
int add (int sec, int min, int hrs, int totalHrs, int totalMins, int totalSecs)
{
int result;
result = totalSecs += sec;
result = totalMins += min;
result = totalHrs += hrs;
result = totalMins = totalSecs % 60;
result = sec = totalSecs %60;
result = totalHrs = totalMins /60;
return result;
}
// Done with all the songs. Print the total time.
int printTime (int totalHrs, int totalMins, int totalSecs)
{
cout << "Total: ";
cout << setfill('0') << totalHrs << ':' << setw(2) << totalMins << ':' << setw(2) << totalSecs << endl;
}
// Convert an integer in the range of 0..99 into a string containing exactly two characters
int twoDigits (char sec, char min, char hrs)
{
char buffer [99] = {0};
sprintf (buffer, "%i", sec);
sprintf (buffer, "%i", min);
sprintf (buffer, "%i", hrs);
}
|