Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Josh Curl
- //11-1-10
- //PG1_16_1
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main()
- {
- double memory, n, total;
- bool total_set = false, memory_set = false;
- char o;
- do
- {
- if(!total_set)
- {
- cout << "Type in the first number" << endl;
- cin >> total;
- total_set = true;
- }
- cout << "Math Operator Options" << endl << "[+]Add [-]Subtract [*]Multiply [/]Divide" << endl << "[s]Square [r]Square Root [p]Power [a]Absolute value" << endl << "[m]Memory options [q]Quit" << endl;
- cin >> o;
- o = tolower(o);
- switch(o)
- {
- case '+':
- cout << "Enter next number: ";
- cin >> n;
- total += n;
- break;
- case '-':
- cout << "Enter next number: ";
- cin >> n;
- total -= n;
- break;
- case '*':
- cout << "Enter next number: ";
- cin >> n;
- total *= n;
- break;
- case '/':
- cout << "Enter next number: ";
- cin >> n;
- while(n == 0)
- {
- cout << "Error: Enter a number thats not zero" << endl;
- cin >> n;
- }
- total /= n;
- break;
- case 's':
- total *= total;
- break;
- case 'r':
- total = sqrt(total);
- break;
- case 'p':
- cout << "Enter next number: ";
- cin >> n;
- total = pow(total, n);
- break;
- case 'a':
- total = abs(total);
- break;
- case 'c':
- total_set = false;
- break;
- case 'm':
- cout << "Memory options:" << endl << "[s]Set [p]Print [c]Clear [+]Add [-]Subtract" << endl;
- cin >> o;
- switch(o)
- {
- case 's':
- cout << "Enter new value for memory: ";
- cin >> n;
- memory = n;
- memory_set = true;
- break;
- case 'p':
- if(memory_set)
- {
- cout << memory << endl;
- }
- else
- {
- cout << "Error: Memory not set" << endl;
- }
- break;
- case 'c':
- memory_set = false;
- break;
- case '+':
- if(memory_set)
- {
- cout << "Enter next number: ";
- cin >> n;
- memory += n;
- }
- else
- {
- cout << "Error: Memory not set" << endl;
- }
- break;
- case '-':
- if(memory_set)
- {
- cout << "Enter next number: ";
- cin >> n;
- memory -= n;
- }
- else
- {
- cout << "Error: Memory not set" << endl;
- }
- break;
- }
- break;
- }
- cout << "Total: ";
- if(total_set)
- {
- cout << total << endl;
- }
- else
- {
- cout << "<cleared>" << endl;
- }
- }
- while(o != 'q');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement