Hello. I started learning C today, and found myself trying to write a simple calculator program. However, after attempting the operation "5+4", I get the answer 32704. Using other operations produces similar results. I appreciate any help you can give me.
EDIT:
Here's the code in a nice tag:
Code:#include <stdio.h> #include <stdlib.h> int main() { int q; int q2; int q3; char w[16]; char o[16]; puts("Enter the first number:"); scanf("%s",w); q=atoi(w); puts("Enter the second number:"); scanf("%s",w); q2=atoi(w); puts("Enter the operator:"); scanf("%s",o); if (o == "+") { q3=q+q2; } if (o == "-") { q3=q-q2; } if (o == "/") { q3=q/q2; } if (o == "*") { q3=q*q2; } printf("%d %s %d = %d\n",q,o,q2,q3); return(0); }



LinkBack URL
About LinkBacks


