Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "stdlib.h"
- using namespace std;
- void runPassword();
- double enterTTNum(double &TT);
- void menuSelections();
- void forLoop();
- void precheckLoop();
- void postcheckLoop();
- void exit();
- int main(){
- runPassword();
- return 0;
- }
- void runPassword(){
- int correct_password = 1998;
- int password = 0;
- int attempt = 1;
- while (attempt <= 3){
- cout << "Enter your password to continue: ";
- cin >> password;
- attempt = attempt + 1;
- if (cin.fail()){
- cin.clear();
- //cin.ignore(INT_MAX, '\n'); Doesnt work.
- cout << "Input Error. Numeric values only!" << endl;
- runPassword();
- }
- else if (password != correct_password) {
- cout << "Incorrect password combination. Please Try again." << "\n";
- //runPassword();
- }
- else
- {
- break;
- }
- }
- if (attempt >= 3){
- if (password == correct_password){
- cout << "Access Granted." << endl;
- system("Pause");
- menuSelections();
- }
- else{
- exit(0);
- }
- }
- else{
- cout << "Access Granted." << endl;
- system("Pause");
- menuSelections();
- }
- }
- double enterTTNum(double &TT){
- double selection;
- for (int i = 0; i <30; i++){
- cout << "-";
- }
- cout <<"\n"<< "Enter your choice of the time table: " << endl;
- cin >> TT;
- if (cin.fail()){
- cin.clear();
- //cin.ignore(INT_MAX, '\n'
- cout <<"Input Error. Numeric values only." << endl;
- system("pause");
- system("cls");
- enterTTNum(TT);
- }
- else if (TT < 1 || TT>12){
- cout << "Number has to be between 1 and 12" << endl;
- system("pause");
- system("cls");
- enterTTNum(TT);
- }
- else{
- return TT;
- }
- return TT;
- }
- void menuSelections(){
- int MainMenuOptions;
- do{
- cout << "\n" << "| Menu Items |";
- cout << "\n" << "| |";
- cout << "\n" << "| 1. For Loop (Fixed Loop) |";
- cout << "\n" << "| 2. While (Pre-Check) |";
- cout << "\n" << "| 3. Do Loop (Post-Check) |";
- cout << "\n" << "| |";
- cout << "\n" << "| 0. Exit Program |";
- cout << "\n" << "| |";
- for (int i = 0; i < 30; ++i){
- cout << "-";
- }
- cout << "\n" << "Please select an option: ";
- cin >> MainMenuOptions;
- if (cin.fail()){
- cin.clear();
- //cin.ignore(INT_MAX, '\n'
- cout << "Input Error, Numeric values only." << endl;
- system("pause");
- system("cls");
- menuSelections();
- }
- else{
- switch (MainMenuOptions){
- case 1:
- forLoop();
- break;
- case 2:
- precheckLoop();
- break;
- case 3:
- postcheckLoop();
- break;
- case 0:
- exit();
- break;
- default:
- cout << "\n" << "Invalid Option entered" << "\n";
- system("pause");
- system("cls");
- menuSelections();
- break;
- }
- }
- } while (MainMenuOptions != 1 && MainMenuOptions != 2 && MainMenuOptions != 3 && MainMenuOptions !=0);
- }
- void forLoop(){
- int Answer;
- double TT = 0;
- enterTTNum(TT);
- for (int i = 1; i < 12; i++){
- Answer = TT * i;
- cout << TT << " * " << i << " = " << Answer << endl;
- }
- system("pause");
- exit();
- }
- void precheckLoop(){
- int Answer;
- double TT=0;
- enterTTNum(TT);
- int i = 0;
- while ( i < 12){
- i = i + 1;
- Answer + TT * i;
- cout << TT << " * " << i << " = " << Answer << endl;
- }
- system("pause");
- exit();
- }
- void postcheckLoop(){
- int Answer;
- double TT;
- enterTTNum(TT);
- int i = 0;
- do{
- i = i + 1;
- Answer = TT * i;
- cout << TT << " * " << i << " * " << Answer << endl;
- } while (i < 12);
- system("pause");
- exit();
- }
- void exit(){
- char choice;
- cout << "\n\n\n" << "Do you want to run the program again? (Y or N): ";
- cin >> choice;
- if (choice == 'Y' || choice == 'y'){
- system("cls");
- menuSelections();
- }
- else if (choice == 'N' || choice == 'n'){
- exit(0);
- }
- else{
- cout << "\n" << "Invalid letter. Only accept Y or N" << "\n";
- exit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement