Advertisement
BaSs_HaXoR

Time past Midnight in seconds (C++)

Feb 4th, 2015
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. /*
  2. @Project: Write a program that uses a function that tasks 3 arguments
  3. of time(hours, minutes, and seconds). The function will take those parameters,
  4. calculate, and display the # of seconds that have elapsed since midnight.
  5. The program should allow the user to enter in the arguments.
  6. @Author: BaSs_HaXoR
  7. @Date: 02/04/15
  8. @Class: Intro to C++ Programming
  9. */
  10.  
  11. #include <iostream>
  12.  
  13. using namespace std;
  14.  
  15. const int MIDNIGHT = 12;
  16. const int MAXSEC = 60;
  17. const int MAXMIN = 60;
  18. int Hours;
  19. int Minutes;
  20. int Seconds;
  21.  
  22. void _checkHours(int hours)
  23. {
  24.     if(hours >= 24)
  25.     {
  26.         Hours = hours % 12;
  27.     }
  28.     else
  29.     {
  30.         Hours = hours;
  31.     }
  32. }
  33.  
  34. void _checkMinutes(int minutes)
  35. {
  36.     if(minutes >= MAXMIN)
  37.     {
  38.         Minutes = minutes % 60;
  39.     }
  40.     else
  41.     {
  42.         Minutes = minutes;
  43.     }
  44. }
  45.  
  46. void _checkSeconds(int seconds)
  47. {
  48.     if(seconds >= MAXSEC)
  49.     {
  50.         Seconds = seconds % 60;
  51.     }
  52.     else
  53.     {
  54.         Seconds = seconds;
  55.     }  
  56. }
  57.  
  58. int _returnSeconds()
  59. {
  60.     int output;
  61.     output = Hours * MAXSEC * MAXMIN;
  62.     output = output + (Minutes * MAXMIN);
  63.     output = output + Seconds;
  64.     return output;
  65. }
  66. void _sinceMidnight(int hours, int minutes, int seconds)
  67. {
  68.     _checkHours(hours);
  69.     _checkMinutes(minutes);
  70.     _checkSeconds(seconds);
  71. }
  72.  
  73. int main(int args, char *argv[])
  74. {
  75.     cout<<"Please enter hours: ";
  76.     cin >> Hours;
  77.     cout<<"Please enter minutes: ";
  78.     cin >> Minutes;
  79.     cout<<"Please enter seconds: ";
  80.     cin >> Seconds;
  81.    
  82.     _sinceMidnight(Hours, Minutes, Seconds);
  83.     cout<<"Time past Midnight: "<<Hours<<" hours, "<<Minutes<<" minutes, "<<Seconds<<" seconds."<<endl;
  84.     cout<<"Time past Midnight (In Seconds): "<< _returnSeconds()<<endl;
  85.     cin.get();
  86.    
  87. }
  88. //BaSs_HaXoR
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement