#include<stdio.h> int main(){ printf("MY SIMPLE CALCULATOR"); printf("\nInstructions"); char name[50]; printf("\n Ent
6/24/2022 10:21:35 PM
Chike Chewakondi
49 Answers
New AnswerChike Chewakondi please show us your attempt. I gather this is a c code but you attempted to put your code in the title verses the description part of the question section of the thread.
Chike Chewakondi and BroFar , here's the right way to add code: 1. Enter the code in Code Playground 2. Save it as public 3. In the question description, tap "+" button 4. Select code If you already posted the question, just edit it. Also, use tags to inform the language. "please" and "really" give absolutely no information.
Bro, you can use these methods for clear keyboard buffer in c :- 1. scanf(" %c",&op); 2. fflush(stdin); scanf("%c,&op);
Can you grab a copy and post it here in the thread so we can see how to help you? Chike Chewakondi
#include<stdio.h> int main(){ printf("MY SIMPLE CALCULATOR"); printf("\nInstructions"); char name[50]; printf("\n Enter your name:"); gets(name); printf("\n\n %s,To perform an operation,Enter 1""\n -and,To perform a summation,""Enter 2:",name); int option; scanf("\n%d",&option); if(option==1){ printf("\n You have chosen option=%d,%s",option,name); printf("\n So,To perform an operation for only two numbers,Enter one of the following operators"); char operator; printf("\n [+,-,*,/]"); printf("\n Operator:"); scanf("%c", &operator); double num1,num2; printf ("\n %s,Please enter first number value:",name); scanf("%lf",&num1); printf ("\n and second number value:"); scanf("%lf",&num2); double result; switch(operator){ case '+': result=num1+num2; printf("\n%s, your result is %.1lf", name,result); break; case '-': result=num1-num2; printf("\n%s, your result is %.1lf",name,result); break; case '*': resul
Looks like you need to have knowledge of all inputs ahead of time Chike Chewakondi and enter them in the beginning. https://code.sololearn.com/cbn5meiBk8IV/?ref=app
I thought it was just exactly there we had to input a value, but it always seemed to skip that line
Chike Chewakondi first error change gets to scanf("%s", &name); 1 error down option 1 and option 2 seem to be fine it doesn't appear to be picking up the operator num1 and num2 appear to be floats try it with int as %d vs %lf not sure if you have other inputs / scanf(s) I missed.
Chike Chewakondi here is mine from 3 years ago https://code.sololearn.com/cjxo10O7D1t0/?ref=app
Thanks for the tip but if you remove the part of my code which operates, it works well but when you insert that in another conditional, the problem starts
#include<stdio.h> int main() { printf("MY SIMPLE CALCULATOR"); printf("\n To perform an operation" "\n Enter one of the following operators"); printf("\n [+,-,*,/]"); char operator; printf("\n Operator:"); scanf("%c",&operator); double num1,num2; printf ("\n Enter first number value:"); scanf("%lf",&num1); printf("Num 1= %lf",num1); printf ("\n Enter second number value:"); scanf("%lf",&num2); printf("\nNum 2= d%",num1); double result; printf("\n The result is %lf",result); switch(operator){ case '+': result=num1+num2; printf("\n The result is %lf",result); break; case '-': result=num1-num2; printf("\n The result is %lf",result); break; case '*': result=num1*num2; printf("\n The result is %lf",result); break; case '/': result=num1/num2; printf("\n The result is %lf",result); break; default: printf("Invalid input"); } return 0; } As this