- 2

#include<stdio.h> int main(){ printf("MY SIMPLE CALCULATOR"); printf("\nInstructions"); char name[50]; printf("\n Ent

Error, please help correct

24th Jun 2022, 10:21 PM
Chike Chewakondi
49 ответов
+ 1
What did you change?
25th Jun 2022, 8:32 PM
Emerson Prado
Emerson Prado - avatar
+ 2
Chike 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.
24th Jun 2022, 10:26 PM
BroFar
BroFar - avatar
+ 2
Instead of using multiple if else use switch case statements
26th Jun 2022, 11:26 AM
Anand</left>
Anand</left> - avatar
+ 1
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.
25th Jun 2022, 3:08 AM
Emerson Prado
Emerson Prado - avatar
25th Jun 2022, 7:59 PM
Chike Chewakondi
+ 1
Bro, you can use these methods for clear keyboard buffer in c :- 1. scanf(" %c",&op); 2. fflush(stdin); scanf("%c,&op);
26th Jun 2022, 2:27 PM
Deepak Rawat
0
Really sorry for that, thanks for the concern
24th Jun 2022, 10:27 PM
Chike Chewakondi
0
I have difficulties to post that
24th Jun 2022, 10:29 PM
Chike Chewakondi
0
Can you grab a copy and post it here in the thread so we can see how to help you? Chike Chewakondi
24th Jun 2022, 10:44 PM
BroFar
BroFar - avatar
0
#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
24th Jun 2022, 10:45 PM
Chike Chewakondi
0
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
24th Jun 2022, 10:50 PM
BroFar
BroFar - avatar
0
So how do l go about
24th Jun 2022, 10:52 PM
Chike Chewakondi
0
I thought it was just exactly there we had to input a value, but it always seemed to skip that line
24th Jun 2022, 10:53 PM
Chike Chewakondi
0
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.
24th Jun 2022, 11:03 PM
BroFar
BroFar - avatar
0
What if the inputted num values are decimal points
24th Jun 2022, 11:08 PM
Chike Chewakondi
0
It's still skipping the operator read part, what do you propose sir
24th Jun 2022, 11:09 PM
Chike Chewakondi
24th Jun 2022, 11:38 PM
BroFar
BroFar - avatar
0
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
24th Jun 2022, 11:41 PM
Chike Chewakondi
0
#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
24th Jun 2022, 11:44 PM
Chike Chewakondi
0
Emerson Prado, thanks for the tip, could you give some concerning my code
25th Jun 2022, 7:29 PM
Chike Chewakondi