101 lines
2.3 KiB
C++
101 lines
2.3 KiB
C++
/*
|
|
* Clock app for Project One
|
|
* Menu.h header file
|
|
*
|
|
* Date: 2022/03/16
|
|
* Author: Cody Cook
|
|
*/
|
|
|
|
#pragma once // only read this file once
|
|
#include "Main.h" // get clearScreen function
|
|
#include "Clock.h" // use of clock functions
|
|
#include <iostream> // use of cin, cout
|
|
#include <string> // use of string
|
|
#include <cstring> // use of string functions
|
|
|
|
string menuCommand = "Don't Exit";
|
|
;
|
|
|
|
const char *menuItems[] = {"Add One Hour", "Add One Minute", "Add One Second", "Exit Program"};
|
|
|
|
void printMenu(const char *strings[], unsigned int numStrings, unsigned char width)
|
|
{
|
|
|
|
// print width of *, followed by a new line; top of table
|
|
cout << nCharString(width, '*') << endl;
|
|
|
|
// for each of the strings
|
|
for (unsigned int i = 0; i < numStrings; i++)
|
|
{
|
|
|
|
// set this string to s
|
|
string s = strings[i];
|
|
|
|
// create a menu option
|
|
cout << "* " << i + 1 << " - " << s << nCharString(width - s.length() - 7, ' ') << "*" << endl;
|
|
|
|
// after every line, except the last line, add a * one each side of a line of spaces
|
|
if (i < numStrings - 1)
|
|
{
|
|
cout << endl;
|
|
}
|
|
}
|
|
// print width of *, followed by a new line; bottom of table
|
|
cout << nCharString(width, '*') << endl;
|
|
}
|
|
|
|
unsigned int getMenuChoice(unsigned int maxChoice)
|
|
{
|
|
// variable for user's selection in menu
|
|
unsigned int choice;
|
|
|
|
// prompt user for option
|
|
cin >> choice;
|
|
|
|
// if the user puts a bad value, make them enter it again
|
|
while (choice < 1 || choice > maxChoice)
|
|
{
|
|
cout << "Invalid choice, please try again: ";
|
|
clearCin();
|
|
cin >> choice;
|
|
}
|
|
|
|
// return the valid choice option
|
|
return choice;
|
|
}
|
|
|
|
void mainMenu()
|
|
{
|
|
// variable for user's selection in menu
|
|
unsigned int menuChoice = getMenuChoice(4);
|
|
|
|
// options 1-3 control the clock
|
|
// option 4 exits the program
|
|
switch (menuChoice)
|
|
{
|
|
case 1:
|
|
// add one hour to the clock, then show the clock
|
|
addOneHour();
|
|
displayClocks(hour, minute, second);
|
|
break;
|
|
case 2:
|
|
// add one minute to the clock, then show the clock
|
|
addOneMinute();
|
|
displayClocks(hour, minute, second);
|
|
break;
|
|
case 3:
|
|
// add one second to the clock, then show the clock
|
|
addOneSecond();
|
|
displayClocks(hour, minute, second);
|
|
break;
|
|
case 4:
|
|
// exit the program
|
|
menuCommand = "exit";
|
|
break;
|
|
default:
|
|
// if the user puts a bad value, make them enter it again
|
|
cout << "Invalid choice, please try again." << endl;
|
|
break;
|
|
}
|
|
}
|