0

(question in C)Help explain to me please.Thanks :)

float a = 0.7; If (0.7 > a){ Printf("hi")}; Else{ Printf("hello")};

14th May 2020, 6:12 AM
Burn
Burn - avatar
6 Respostas
+ 1
Yes Sorry i didnt take a close look anyway the problem is you compare a double with a float When you write 0.7 without 'f' its actually become a 'double' not a 'float' If you want to get it right add f to '0.7f' or you could change 'float a' to 'double a'
15th May 2020, 10:52 AM
Yahya LAZREK
Yahya LAZREK - avatar
+ 1
Yahya LAZREK owhhh...thanks alot bro.
15th May 2020, 11:07 AM
Burn
Burn - avatar
0
Is 0.7 > 0.7 ? Actually Not its false So you will get hello . To get true try : if(0.7 == a)
14th May 2020, 1:03 PM
Yahya LAZREK
Yahya LAZREK - avatar
0
Yahya LAZREK the answer was hi not hello... that was why I asked cuz it sounded weird for me
15th May 2020, 7:37 AM
Burn
Burn - avatar
0
Because you didn't write the Code Correctly Look here at line 3 in your Code : Printf it should be printf and ';' should be after ("hi"); not ("hi")}; The same thing for else and the last line. Try this : float a=0.7; if(0.7 > a) { printf("hi"); } else { printf("hello"); } //it should work propobly
15th May 2020, 10:29 AM
Yahya LAZREK
Yahya LAZREK - avatar
0
Yahya LAZREK yup sorry I had my syntax messed up as I'm still relatively new 😀 but the answer is still hi ...that is the part I don't understand why
15th May 2020, 10:39 AM
Burn
Burn - avatar