I have to create a program that acts as a computer. You start with a total of zero, then ask for an arithmetic function with an additional number. So, let's say I am going to add 7. It would then keep a running total using a do..while loop of the transactions, and then cancel if the user inputs X.
Here is my code:
#include <iostream> #include <string> using namespace std; int main() { double total = 0, number = 0; string math; do { cout << "Current total is " << total << endl; cout << "Enter an operation: + - * / (or enter X to exit): "; cin >> math; cin.ignore(); if (math == "X") break; cout << "Enter a number: "; cin >> number; cin.ignore(); } while ((math != "x") || (math != "X") || (math == "+") || (math == "-") && (math == "*") || (math == "/")); if (math == "+") { cout << (total + number) << endl; } else if (math == "-") { cout << (total - number) << endl; } else if (math == "*") { cout << (total * number) << endl; } else if (math == "/") { cout << (total / number) << endl; } }
I can't get the total to work. It keeps giving me a 0 total. Any ideas?
Edited by Supernature, 07 July 2010 - 06:53 PM.