Post by speedyclock on Jan 23, 2011 2:01:31 GMT
//Okay, set up primary include statements and predefined functions
#include <iostream>
#include <CMATH>
//Set up our Primary Function, this will not be a class, but a simple program
int main()
{
//Now that we got some space, let's get the namespace down
using namespace std;
//Now for the Variables
int op;
int cn;
int sn;
int co;
int constant = 1;
cout << "Enter your first number! : ";
cin >> cn;
cout << endl;
//Now to get the main loop up, I will use a while loop
while (constant == 1){
cout << "Enter 1 to add, 2 to subtract, 3 to abort, Please enter an null second number after aborting for the program to shut down : ";
cin >> op;
cout << endl << "Now enter your second number pl0x : ";
cin >> sn;
cout << endl;
if (op == 1) {
cn = cn + sn;
}
else if (op == 2) {
cn = cn - sn;
}
else if (op = 3) {
cout << "Program Aborted";
cout << endl;
system("pause");
return 0;
}
constant = 2;
}
//Now we have the standard startup statements up. Now we are going to make it so the calculator continues to calculate
while (constant == 2) {
cout << "Current number : " << cn << "!" << " What is your next Operation (Add 1, Sub 2) : ";
cin >> op;
cout << endl << "Now what is your second number :";
cin >> sn;
cout << endl;
if (op == 1){
cn = cn + sn;
}
else if (op == 2) {
cn = cn - sn;
}
}
}
Run on DebC++, automatic writer and compiler for C++
Tell me what you think
I know that other operations can be easily programmed into this. But it's too much of a pain and this was merely a proof of concept. It took me 20 minutes.