Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- @Project: Write a program that uses a function that tasks 3 arguments
- of time(hours, minutes, and seconds). The function will take those parameters,
- calculate, and display the # of seconds that have elapsed since midnight.
- The program should allow the user to enter in the arguments.
- @Author: BaSs_HaXoR
- @Date: 02/04/15
- @Class: Intro to C++ Programming
- */
- #include <iostream>
- using namespace std;
- const int MIDNIGHT = 12;
- const int MAXSEC = 60;
- const int MAXMIN = 60;
- int Hours;
- int Minutes;
- int Seconds;
- void _checkHours(int hours)
- {
- if(hours >= 24)
- {
- Hours = hours % 12;
- }
- else
- {
- Hours = hours;
- }
- }
- void _checkMinutes(int minutes)
- {
- if(minutes >= MAXMIN)
- {
- Minutes = minutes % 60;
- }
- else
- {
- Minutes = minutes;
- }
- }
- void _checkSeconds(int seconds)
- {
- if(seconds >= MAXSEC)
- {
- Seconds = seconds % 60;
- }
- else
- {
- Seconds = seconds;
- }
- }
- int _returnSeconds()
- {
- int output;
- output = Hours * MAXSEC * MAXMIN;
- output = output + (Minutes * MAXMIN);
- output = output + Seconds;
- return output;
- }
- void _sinceMidnight(int hours, int minutes, int seconds)
- {
- _checkHours(hours);
- _checkMinutes(minutes);
- _checkSeconds(seconds);
- }
- int main(int args, char *argv[])
- {
- cout<<"Please enter hours: ";
- cin >> Hours;
- cout<<"Please enter minutes: ";
- cin >> Minutes;
- cout<<"Please enter seconds: ";
- cin >> Seconds;
- _sinceMidnight(Hours, Minutes, Seconds);
- cout<<"Time past Midnight: "<<Hours<<" hours, "<<Minutes<<" minutes, "<<Seconds<<" seconds."<<endl;
- cout<<"Time past Midnight (In Seconds): "<< _returnSeconds()<<endl;
- cin.get();
- }
- //BaSs_HaXoR
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement