Hello we are learning to use functions in my class, but despite my lectures and reading, I still am struggling with this particular assignment. The basic gist of the assignment is we are to program security protocols into a "time machine" that does not allow the machine to travel more than 12 hours in the future or the past, and if the user input is even 1 minute more than 12 hours, it will not initialize and will ask for a new input. I'm a bit confused about a few things here.
My professor is requiring we use certain variables to fit with the program, for example, int c_hrs, int c_mins, bool c_am, int t_hrs, int t_mins, bool t_am all in a function that computes the time difference between the current time, entered by the user, and the target time, also entered by the user.
What is the purpose of these boolean variables? I am under the assumption that they are to store the information when the user is asked if the time is AM or PM but why use bool for that?
Also, my code is 1) Ignoring that the minutes input is one digit and displaying "10" when the user enters "1" or "01" and 2) is ignoring the am or pm entry
My code is not anywhere near complete and a bit of a mess but I am just working on the skeleton of the program right now and am saving the computations, etc. for later when I figure out how to establish my main processes.
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
|
#include <iostream>
#include <cmath>
using namespace std;
int compute_time_difference(int c_hrs, int c_mins, bool c_am, int t_hrs, int t_mins, bool t_am);
int print_past();
int print_future();
int print_securityProtocol();
int main()
{
int c_hrs, c_mins;
bool c_am;
int t_hrs;
int t_mins;
bool t_am;
char ct, Y, N, y, n;
bool g_stop = true;
cout << "Welcome to Po Sled" << endl;
cout << "\tSystem booting..." << endl;
do {
cout << "\n\tEnter current time below: " << endl;
cout << "\t>Enter hour: ";
cin >> c_hrs;
if (c_hrs > 12 || c_hrs < 0) {
cout << "Error: Please enter an hour in the range [1, 12]: ";
cin >> c_hrs;
}
cout << "\t>Enter minutes: ";
cin >> c_mins;
if (c_mins > 59 || c_mins < 0) {
cout << "Error: Please enter minutes in the range [0, 59]: ";
cin >> c_mins;
}
cout << "\t>Is it AM or PM?: ";
cin >> c_am;
cout << "\n\tCurrent system time set to " << c_hrs << ":" << c_mins << c_am;
cout << "\n\t\tIs this correct (Y or N)?";
cin >> ct;
if (ct == N || ct == n) {
continue;
}
else {
cout << "\n\tSystem initializing and TARDIS unit warming...." << endl;
cout << "\tThe Po Sled is engaged and ready for input." << endl;
}
cout << "\tEnter target time below: " << endl;
cout << "\t>Enter Hour: ";
cin >> t_hrs;
cout << "\t>Enter minutes: ";
cin >> t_mins;
} while (g_stop = false);
return 0;
}
int compute_time_difference(int c_hrs, int c_mins, bool c_am, int t_hrs, int t_mins, bool t_am)
{
}
int print_past() {
cout << "Security Protocols Engaging" << endl;
}
int print_future() {
cout << "Security Protocols Engaging" << endl;
}
int print_securityProtocol() {
cout << "Security Protocols Engaging" << endl;
}
|
The functions currently do nothing because I've just started and haven't added anything to them yet other than the initial message.