Just started learning C++ and I'm not so l337 at programming.
Anyways, by the end of my studies I will make a version 2 which will be a full blown calculator, or way better than this.
I plan on letting the user input how many numbers they would like to do math with, have a number selection instead of an operator selection for ease, (I could do that now) storing some of the variables in a enum and writing a switch statement for the inputs, and some other nerdy stuff that I either couldn't / didn't want to do the first go around.
Anywho, I am just posting this so that if you are starting in C++ you can look at this and ponder.
God this program is rough haha:
- Code: Select all
#include <iostream>
#include <string>
/*All of the functions (a, b, c, d, e, and f) are aligned on the far left of the page by theirself for easy identification
*******************************************************************************
* _______ ____ _\ Fear no man /_ *
* ||||\\\\ |||| _OOO\ that /OOO_ *
* |||| \\\\ |||| OOOOO\ bleeds /OOOOO *
* |||| \\\\ |||| OOO __________ OOO @_Ninjex_ ___ ___ *
* |||| \\\\ |||| |||| |||||||||||| ||||||||||||||| \\\\ //// *
* |||| \\\\ |||| |||| |||| |||| |||| ||____|| \\\\ //// *
* |||| \\\\ |||| |||| |||| |||| |||| |||||||| ||||||| *
* |||| \\\\ ||||___||||___|||| |||| |||| ||________ //// \\\\ *
* |||| \\\\|||||||||||||||||| |||| |||| |||||||||||//// \\\\ *
***************************************||||___||||*****************************
*|||||||||||*
*************
*/
int main()
{
using namespace std;
string x; //This variable will store answer variable for the password prompt
string y; //This variable will be used to store user input for the operator choice
/////////////////////////////////////////////////////////////////////////////////////
// The following variables are used to store the operator & string values /////
///////////////////////////////////////////////////////////////////////////////////
string plus = "+"; //////////////////////////////////////////////
string minus = "-"; //////////////////////////////////////////////
string multi = "*"; //////////////////////////////////////////////
string sBack = "back"; //////////////////////////////////////////////
string sReturn = "exit"; //////////////////////////////////////////////
string sQuit = "quit"; //////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
a: //Login function - Here we ask the user for the password, and give the option to exit the program
cout << "If you wish to close the program, type: 'quit'"; cout << endl;
cout << "Please enter the password to continue!"; cout << endl;
cin >> x; //Setting x equal to user input, for password validation checking
if (x == sQuit) //If user input is 'quit' we go to f: the exit function
{
goto f;
}
if (x != "ninjex") //If user input is not 'ninjex' we go to a: the login function
{
goto a;
}
else
{
cout << "How did you know the password was "; cout << x; cout << "?"; cout << endl;
b: //Selection function - Here we get user input of an operator that they whish to carry out
cout << "Please enter the operator you wish to use: +, -, or *"; cout << endl;
cout << "You may type 'exit' to leave or 'back' to return to the login"; cout << endl;
cin >> y;
if (y == plus) // // // //If user input is '+' we go to c: the addition function
{
goto c;
}
else if (y == minus) //If user input is '-' we go to d: the subtraction function
{
goto d;
}
else if (y == multi) //If user input is '*' we go to e: which is the multiplication function
{
goto e;
}
else if (y == sBack) //If user input is 'back' we go to a: the login function
{
goto a;
}
else if (y == sReturn) //If user input is 'exit' we go to f: the exit function
{
goto f;
}
else //If user input was not a valid choice, we loop them back to b: the selection function
{
goto b;
}
}
c: //addition function - anum and anum2 store the value of the user's numbers
cout << "Please enter a number: ";
int anum;
cin >> anum;
cout << "Please enter another number: ";
int anum2;
cin >> anum2;
cout << "The sum of: "; cout << anum; cout << " and "; cout << anum2; cout << " is: "; cout << anum + anum2; cout << endl; //Printing - The sum of: anum and anum2 is: anum + anum2
goto b;
d: //substraction function - bnum and bnum2 store the value of the user's numbers
cout << "Please enter a number: ";
int bnum;
cin >> bnum;
cout << "Please enter another number: ";
int bnum2;
cin >> bnum2;
cout << bnum; cout << " subtracted by "; cout << bnum2; cout << " is: "; cout << bnum - bnum2; cout << endl; //Printing - bnum subtracted by bnum2 is: bnum - bnum2
goto b;
e: //multiplication function - mnum and mnum2 store the value of the user's numbers
cout << "Please enter a number: ";
int mnum;
cin >> mnum;
cout << "Please enter another number: ";
int mnum2;
cin >> mnum2;
cout << mnum; cout << " multiplied by "; cout << mnum2; cout << " is: "; cout << mnum * mnum2; cout << endl; //Printing - mnum multiplied by mnum2 is: mnum * mnum2
goto b;
f: //Exit function
return 0; //Exits the program
}




