+ 2

please help me it gives me 0 as a result what is wrong in this code

#include<stdio.h> int main(){ int s,t,c,b; float x,y; printf("enter 2 numb...\n"); scanf("%f%f",&x,&y); printf("choose the type of calc u want to do\n"); printf("1.toplama\n2.cıkarma\n3.bolme\n"); scanf("%d",&s); switch(s) case 1:{ t=x+y; printf("toplam :%f",t); break; case 2: c=x-y; printf("cikarma:%f",c); break; case 3: b=x/y; printf("bolum= %f\n",b); break; default: printf("please enter right things.."); break; } }

3rd Apr 2020, 12:22 PM
Abc def
Abc def - avatar
2 Answers
+ 1
You are using floats and assigning float to int. This will convert the floats to integral values. So if the result is between 0 and 1, it will give 0. you can use float instead of int. Try it and see if it solves the problem
3rd Apr 2020, 12:43 PM
Salman Nazeer
Salman Nazeer - avatar
0
You have to use %d format specifier in place ho %f because t, c and b are "int" type. Like : printf(toplam: %d,t);
5th Apr 2020, 12:01 PM
Zebi Zebi
Zebi Zebi - avatar