Ok, I made a program that can get the operator and the variables, but really, I like it to be more of a real calculator. You know, where you can even more variables then just the preset of them ( the 2 vabls, and the oper. ). Anyone have a idea how this would be done? I was thinking of using strings, and using the "find" funchion, but really, I dont know how to go about it that way either. Any help would be most helpful.
Code:#include <c:\tt.h> using namespace std; int main () { clrscr(); float a, b, result; char oper, ans; cout<<" 7 8 9 +\n 4 5 6 -\n 1 2 3 *\n 0 . /\n"; do { cout<<"Enter first number, operator, second number: "; cin>>a>>oper>>b; switch (oper) { case '+': result=a+b; break; case '-': result=a-b; break; case '*': result=a*b; break; case '/': result=a/b; break; default: cout<<"Error"; } cout<<"Answer = "<<result; cout<<"\nDo another (y/n)? "; cin>>ans; } while (ans=='y'); getchar(); }



LinkBack URL
About LinkBacks



It is my favourite, and it works with a stack, and it is easy to write a simple version of it. Then some additional functions like duplicating the last element in the stack, swaping the to last etc. should be implemented to make an even better calculator!