-
-
Save abonander/29dbb51590ae6c238a866b8c9f53e6ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//calculator by jake molina | |
//includes iostream | |
#include <iostream> | |
//Standard namespace | |
using namespace std; | |
void main() | |
{ | |
//Declare the variables | |
float Number_1; | |
float Number_2; | |
float Result; | |
int Which_Calculation; | |
// Give Instructions. | |
cout << "Choose a task. Press 1 to add, 2 to subtract, 3 to multiply, 4 to divide then press enter" << endl; | |
cin >> Which_Calculation; | |
//Get numbers | |
cout << "Please enter the first number then press enter." << endl; | |
cin >> Number_1; | |
cout << "Please enter the second number then press enter ." << endl; | |
cin >> Number_2; | |
switch (Which_Calculation) { | |
//Addition if command | |
case 1: | |
Result = Number_1 + Number_2; | |
break; | |
//Subtract if command | |
case 2: | |
Result = Number_1 - Number_2; | |
break; | |
//Multiply if command | |
case 3: | |
Result = Number_1 * Number_2; | |
break; | |
//Devide if command | |
case 4: | |
Result = Number_1 / Number_2; | |
break; | |
// Invalid/unknown command | |
default: | |
cout << "Invalid command entered. Exiting." << endln; | |
return; | |
} | |
//Prints Answer | |
cout << "The answer is..." << endl; | |
//Print the result | |
cout << Result << endl; | |
system("PAUSE"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment