New Project... need help please:
Attached is the instructions.
Here is what I have so far and having trouble:
Code:#include <iostream> using namespace std; //Write a simple calculator program. Ask the user if s/he wants to add ('+') subtract ('-'), multiply ('*') or divide ('/') //and then ask for the number. Perform the operation with the given number. Start the "display" at zero. Stop when //the user enters 'X' (for exit). Use a Do..While loop and "if" statements. int main() { double total = 0, n = 0; char operation = ' '; cout << "Current total is 0" << endl; //Asking for user input do { cout << "Enter an operation: + - * / (or enter X to exit): "; cin >> operation; if (operation == 'X') { break; } if ((operation != '+') && (operation != '-') && (operation != '*') && (operation != '/')) do { cout << "Enter an operation: + - * / (or enter X to exit): "; cin >> operation; } while ((operation != '+') && (operation != '-') && (operation != '*') && (operation != '/')); cout << "Enter a number. " ; cin >> n; if (operation == '/') do { cout << "Can not divide by zero!" << endl; cout << "Current total is " << total << endl; } while (n = 0); else cout << "Current total is "; if (operation == '+') total = (total + n); if (operation == '-') total = (total - n); if (operation == '*') total = (total * n); if (operation == '/') total = (total / n); cout << total << endl; } while (operation != 'X'); }



LinkBack URL
About LinkBacks



