Make a single use calculator!
Posted: Thu Jun 24, 2010 6:53 am
Why hello... Yes it's been quite awhile since I've posted.. But I have been very busy. Anyway!
today I am hear to talk about making a calculator. It can do anything.. (Besides decimal numbers and fractions)
But the basic Addition, Multiplication, subtraction, and division. Let us take a look shall we?
First off start with your basic requirements.
Here we are:
Remember only REAL numbers work no decimals or fractions.
Now in order to separate my different types of problems and make them accessible by command using numbers I will use a case/switch method here.
I made sure I labeled each equation correctly so our user knows what he is doing. Unfortunately in order to use this program again it will have to be restarted. Covering this fix I shall post later on... Below I have attached my program for anyone to use... Thanks! Post any feedback and comments!
Mini Calculator - 575 Kb
-Duggypker
EDIT: I forgot to mention in case they put a number besides 1-4. to prevent something bad from happening put this:
today I am hear to talk about making a calculator. It can do anything.. (Besides decimal numbers and fractions)
But the basic Addition, Multiplication, subtraction, and division. Let us take a look shall we?
First off start with your basic requirements.
Code: Select all
Underneath int main(){ create three new integers, I named mine a, b, and c#include <iostream>
using namespace std;
int main(){
}
Here we are:
Code: Select all
Next we will add our function that allows our user to select which type of problem.
#include <iostream>
using namespace std;
int main(){
int a;
int b;
int c;
}
Code: Select all
Now that our user can select the type of problem. Let's move onto the actual equations.#include <iostream>
using namespace std;
int main(){
int a;
int b;
int c;
cout << "What type of equation?\n";
cout << " 1. Addition\n";
cout << " 2. Subtraction\n";
cout << " 3. Multiplication\n";
cout << " 4. Division\n";
cin >> a;
}
Remember only REAL numbers work no decimals or fractions.
Now in order to separate my different types of problems and make them accessible by command using numbers I will use a case/switch method here.
Code: Select all
All that switch(a) { does is reads whatever the user put in as a example: 1 would go to case 1.#include <iostream>
using namespace std;
int main(){
int a;
int b;
int c;
cout << "What type of equation?\n";
cout << " 1. Addition\n";
cout << " 2. Subtraction\n";
cout << " 3. Multiplication\n";
cout << " 4. Division\n";
cin >> a;
switch(a) {
case 1:
cout << "Addition problem\n";
cout << "Enter the first number: ";
cin >> b;
cout << "Now enter the second number: ";
cin >> c;
cout << "Your answer is: " << b+c;
return 0;
case 2:
cout << "Subtraction Problem\n";
cout << "Enter the First Number: ";
cin >> b;
cout << "Now enter the second number: ";
cin >> c;
cout << "Your answer is: " << b-c;
return 0;
case 3:
cout << "Multiplication Problem\n";
cout << "Enter the First Number: ";
cin >> b;
cout << "Now enter the second number: ";
cin >> c;
cout << "Your answer is: " << b*c;
return 0;
case 4:
cout << "Devision Problem\n";
cout << "Enter the First Number: ";
cin >> b;
cout << "Now enter the second number: ";
cin >> c;
cout << "Your answer is: " << b/c;
return 0;
}
}
I made sure I labeled each equation correctly so our user knows what he is doing. Unfortunately in order to use this program again it will have to be restarted. Covering this fix I shall post later on... Below I have attached my program for anyone to use... Thanks! Post any feedback and comments!
Mini Calculator - 575 Kb
-Duggypker
EDIT: I forgot to mention in case they put a number besides 1-4. to prevent something bad from happening put this:
Code: Select all
default:
cout << "That is an invalid selection.. Please restart and try again 1-4.";
return 0;