- 2
#include<stdio.h> int main(){ printf("MY SIMPLE CALCULATOR"); printf("\nInstructions"); char name[50]; printf("\n Ent
Error, please help correct
49 Answers
+ 1
What did you change?
+ 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.
+ 2
Instead of using multiple if else use switch case statements
+ 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.
+ 1
Bro, you can use these methods for clear keyboard buffer in c :-
1. scanf(" %c",&op);
2. fflush(stdin);
scanf("%c,&op);
0
Really sorry for that, thanks for the concern
0
I have difficulties to post that
0
Can you grab a copy and post it here in the thread so we can see how to help you? Chike Chewakondi
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
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
0
So how do l go about
0
I thought it was just exactly there we had to input a value, but it always seemed to skip that line
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.
0
What if the inputted num values are decimal points
0
It's still skipping the operator read part, what do you propose sir
0
Chike Chewakondi here is mine from 3 years ago
https://code.sololearn.com/cjxo10O7D1t0/?ref=app
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
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
0
Emerson Prado, thanks for the tip, could you give some concerning my code