0

# Main operations

I want to write a code which take a,b then calculate one of these(- + / *) main operations and say the result But i can’t What can i do?! https://code.sololearn.com/ciW9hITUNheS/?ref=app

11/6/2019 2:28:55 PM

Laya Mousavi

+2

Laya Mousavi Check for b == 0 before calculating int q = a/b; If b is greater than a then q will always be 0 due to integer division your q should be double double q = (double) a / b; use the correct format specifier when printing it. if(b==0){ printf("error"); else printf("%d",q); } should be if(b==0){ printf("error"); } else { printf("%d",q); } you can skip curly brackets since you have only one line statement Improve your understanding of C language and develop logic. You are making silly mistakes (you did the same in your last program)

+2

Laya Mousavi You will eventually have to improve. Your target should be to become a better programmer not those exercise. Just keep on practicing and be focussed when solving exercises, you will improve.

+1

~ swim ~ i know,i’m sorry about these silly questions i have to post these exercises to my teacher but i can’t solve them😭😭

+1

if(b==0) printf("error\n"); else{ int q=a/b; printf("%d\n",q); } Laya Mousavi Do this and you are good to go. Just make this change in loop.

+1

Avinesh yes the last one works well thanks a lot🙋🏻‍♀️🙋🏻‍♀️🙋🏻‍♀️

+1

0

#include <stdio.h> #include <math.h> int main() { int a,b; printf("what do you want to do?\n"); scanf("%d%d",&a,&b); int q=a/b; if(b==0) printf("error\n"); else printf("%d\n",q); int p=a+b; int m=a-b; int s=a*b; printf("%d\n%d\n%d",p,m,s); return 0; } This works? This is your code I have just made some changes so that you can see the output atleast. Parenthesis after if continuing till the end of else was wrong.

0

Avinesh i checked it for 10,5 it worked but for 10,0 it didn’t

0

~ swim ~ i’m trying,i want to do my best,but i need help , because our exam is next week💔

0

Avinesh ~ swim ~ would you help me with my both last questions,please?!