I know this is a simple program, but I like the idea of what it does and I remember when I first started programming, it's one of the things I really wanted to make.
It's a simple calculator that accepts an undetermined amount of input.
What do ya think? If you can think of ways of improving it, please say. I love critiques.Code:#include <iostream> using namespace std; int main() { double numInput[100]; char signInput[100]; double answer; int x = 0; cout << "Type a standard mathematical operation ending with equals: " << endl << "ex. 5 + 5 =" << endl; cin >> numInput[0]; cin >> signInput[0]; do { x++; cin >> numInput[x]; cin >> signInput[x]; } while (signInput[x] != '='); answer = numInput[0]; for (int y = 0; y <= x; y++) { switch (signInput[y]) { case '+': answer += numInput[y+1]; break; case '-': answer -= numInput[y+1]; break; case '*': answer *= numInput[y+1]; break; case '/': answer /= numInput[y+1]; break; } } cout << "Your answer is: " << answer << endl; return 0; }



LinkBack URL
About LinkBacks


