+ 1

I made a simple calci program in C bt it isn't showing option to enter num1, num2 & operater .

https://code.sololearn.com/cX9vFU5wskBc/?ref=app

4th Sep 2020, 11:30 AM
Aspersh Upadhyay
8 Answers
+ 7
Their is no errors showing in sololearn playground you have to enter all values at run time. Try all three inputs after run . I did changed little bit enter two number theñ operations. #include <stdio.h> int main() { float num1; float num2; char op; float result; printf ("enter the first number:"); scanf ( "%f",&num1); printf ("\nenter the second number:"); scanf("%f",&num2); printf ("\nenter the operation:"); scanf ( " %c",&op); switch (op) { case '-': result = num1 - num2; printf ("\n%f",result); break ; case '+': result = num1 + num2; printf ("\n%f",result); break ; case '*': result = num1 * num2; printf ("\n%f",result); break ; case '/': result = num1 / num2; printf ("\n%f",result); break ; default : printf ("this is not valid:"); } }
4th Sep 2020, 11:51 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 6
If you want to perform all task then remove break statement if u enter + then after + all cases will print automatically becoz their will be no break so
5th Sep 2020, 2:23 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
Hey! Guess the order of your input, then type it box , you will get your expected output easily . Like that: 6 - 3 You'll get: 3.
4th Sep 2020, 2:40 PM
Rupali Haldiya
Rupali Haldiya - avatar
+ 2
By your code: you can guess what operation you want to do, like that if you want to devide to numbers than simply type in box: '3 / 2',if you want to multiply tham, than type '2 * 6', if you want to substraction of two numbers than type '5 - 2' and if you want sum of two numbers than type '2+7' , you'll get you expected output. That's are only examples.. I hope it helps you :-)
5th Sep 2020, 1:38 PM
Rupali Haldiya
Rupali Haldiya - avatar
+ 2
I know this example bt I wanna enter in output section these plus , subs,mult & div . Tell me about that how I will found my expected output ??
5th Sep 2020, 1:57 PM
Aspersh Upadhyay
+ 2
You have to give all the input values at runtime.
5th Sep 2020, 2:18 PM
Sadaf Shaikh
Sadaf Shaikh - avatar
+ 1
Raj Upadhyay You just need to enter the data in the input box in one shot. Like 10 * 23 And then press submit button. Remember to press the enter after each. I already tried and it works.
4th Sep 2020, 11:34 AM
A.B
A.B - avatar
+ 1
Rupali.Bt how will I geuss the order of my input & how will it type in box ? please explain in simple way because I am beginner & I don't know too much in coding
5th Sep 2020, 12:24 PM
Aspersh Upadhyay