Calculator
I'm building a four function calculator and need to know what loop function is the best to use.
Any one got anything?
I've created four separate programs that do one function individually, but I want to put them all together.
Was thinking of "break"...but idk.
Yes, I know I'm new to C++...even though I'm really not, I used to program a lot, stopped for a year or so, then forgot a good amount...
I only remember the basics.
Addition:
Subtraction:
Multiplication:
Division:
Any one got anything?
I've created four separate programs that do one function individually, but I want to put them all together.
Was thinking of "break"...but idk.
Yes, I know I'm new to C++...even though I'm really not, I used to program a lot, stopped for a year or so, then forgot a good amount...
I only remember the basics.
Addition:
Code:
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
//enter first number
double num1;
cout << "Enter first number to be added:";
cin >> num1;
//enter second number
double num2;
cout << "Enter second number to be added:";
cin >> num2;
//calculate answer
double answer;
answer = num1 + num2;
//declare answer
cout << "Answer is:";
cout << answer << endl;
//wait for user to end program to see result
system("PAUSE");
return 0;
}
Code:
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
//enter first number
double num1;
cout << "Enter number to be subtracted from:";
cin >> num1;
//enter second number
double num2;
cout << "Enter second number to be subtracted from first:";
cin >> num2;
//calculate answer
double answer;
answer = num1 - num2;
//declare answer
cout << "Answer is:";
cout << answer << endl;
//wait for user to end program to see result
system("PAUSE");
return 0;
}
Code:
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
//enter first number
double num1;
cout << "Enter first number to be multiplied:";
cin >> num1;
//enter second number
double num2;
cout << "Enter second number to be multiplied:";
cin >> num2;
//calculate answer
double answer;
answer = num1 * num2;
//declare answer
cout << "Answer is:";
cout << answer << endl;
//wait for user to end program to see result
system("PAUSE");
return 0;
}
Code:
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
//enter first number
double num1;
cout << "Enter number to be divided:";
cin >> num1;
//enter second number
double num2;
cout << "Enter second number to divide by:";
cin >> num2;
//calculate answer
double answer;
answer = num1 / num2;
//declare answer
cout << "Answer is:";
cout << answer << endl;
//wait for user to end program to see result
system("PAUSE");
return 0;
}
