Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stdlib.h>
- #include <cctype>
- using namespace std;
- void MENU(); // Function prototype for MENU function
- void Addition(); // Function prototype for Addition function
- void Subtraction(); // Function prototype for Addition function
- void RESTART(); // Function prototype for RESTART function
- //Function prototypes used to keep the code clean and readable.
- int main() //Main function
- {
- MENU(); // MENU first to run in the main
- return 0;
- }
- void MENU() //When called upon the basic main menu should show up.
- {
- int answer; //answer variable used to navigate the menu
- int Addition(); //Function variable (i think) for Addition
- int Subtraction(); //Function variable possible for Subtraction
- cout << " MENU\n"; //Text for the menu reading off the options the user has from 1 to 3
- cout << " 1.ADDITION\n";
- cout << "2.SUBTRACTION\n";
- cout << " 3.EXIT\n";
- cin >> answer; //User enters his answer
- switch(answer){ //Switch runs through its options based on that answer variable
- case 1:// if case 1 is picked then it goes to the addition function
- Addition();
- break;
- case 2:// if 2 is picked then it goes to the subtraction function
- Subtraction();
- break;
- case 3: // If the user enters 3 then it clears screen and ends the program.
- system("cls"); // a poor insecure way to clear the screen before exiting the program,
- //but currently the only way i know how to get it to work the way i desire it to.
- exit(0);
- break;
- default :
- cout << "PLEASE INSIERT 1, 2 OR 3\n";//Prompting user to pick a valid answer
- MENU();//Redirecting user back the MENU function
- }
- }
- void Addition() //When called upon the program should do a basic 2 number addition.
- {
- int fn;
- int sn;
- int sum;
- cout << " ADDITON\n"; //Very simplistic almost DOS like menu for the Addition user interface
- cout << "ENTER YOUR FIRST NUMBER:\n"; //Prompting user for first number
- cin >> fn; // User enters first number
- cout << "\nENTER YOUR SECOND NUMBER:\n"; //Prompting user for first number
- cin >> sn; // User enters second
- sum = fn + sn; //Program adds the two together
- cout << "\nYOUR TOTAL IS: " << sum << endl; //Program prints out sum
- cout << endl;
- RESTART(); // Supposed to ask if the user wants to restart, instead goes straight to menu
- }
- void Subtraction() //Everything here is supposed to act the same as addition
- //except its main purpose is to subtract the second number from the first number
- //but it fails the same way as the Addition function
- {
- int fn;
- int sn;
- int sum;
- cout << " SUBTRACTION\n";
- cout << "ENTER YOUR FIRST NUMBER:\n";
- cin >> fn; //All functions here are the same as addition with the exception it subtracts values rather than adds them
- cout << "\nENTER YOUR SECOND NUMBER:\n";
- cin >> sn;
- sum = fn - sn;
- cout << "\nYOUR TOTAL IS: " << sum << endl;
- cout << endl;
- RESTART(); // same issue happens as soon as it's supposed to hit this bit of code
- }
- void RESTART() //When called upon the program will restart or end the program, or so it should.
- {
- string input;
- cout << "DO YOU WISH TO START OVER? Y/N"; //None of this makes an appearance in the code
- cin >> input;
- if (input == 'y')
- {
- MENU();
- }else if(input == 'n')
- {
- system("cls");// a poor insecure way to clear the screen before exiting the program
- //but currently the only way i know how to get it to work the way i desire it to.
- exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement