+ 3

Find the error below prgrm....

#include <iostream> using namespace std; int main() { int h;cin>>h; float f; f=100*2/h; h=f; if(f>=h+0.5) cout<<h+1; else cout<<h; return 0; }

5th Aug 2020, 9:49 AM
Learner
Learner - avatar
16 Antworten
+ 14
Yes I know it.. it's a type convertion float to int..I just said the raw value of f i.e. 66.67 above :)
5th Aug 2020, 11:28 AM
Aditya
Aditya - avatar
+ 13
Buddy the comparison would be 67>=67.17 which is false.. hence the else case would run :) You have forgot to make 66.67 as 67 in your solution :) hence you are getting wrong output :)
5th Aug 2020, 11:01 AM
Aditya
Aditya - avatar
+ 12
There is no syntax error in your program :) your logic is perfect.. you have forgot to intend / leave space.. between some of the parameters.. and to split in multiple lines :) You can see this https://code.sololearn.com/cIs75Z9uEQ1z/?ref=app
5th Aug 2020, 10:14 AM
Aditya
Aditya - avatar
+ 12
It runs perfectly.. you can take h as 5 and the output should be 40 Try it by writing some were you may get the answer :)
5th Aug 2020, 10:26 AM
Aditya
Aditya - avatar
+ 4
Buddy the comparison would be 67>67.17 which is false.. hence the else case would run :) You have forgot to make 66.67 as 67 in your solution :) hence you are getting wrong output :) Ohk.. pls tell me when we put h=3 then what is the value of f . And.. why....
5th Aug 2020, 11:09 AM
Learner
Learner - avatar
+ 3
You can't post homework or quizzes here; no one is going to just give you the answer for anything.
5th Aug 2020, 10:11 AM
PresidentOfYes12
PresidentOfYes12 - avatar
+ 3
Ohk.. but i want to know why if statement not run in this prgrm??
5th Aug 2020, 10:15 AM
Learner
Learner - avatar
+ 3
I'm not sure why you need to store a float value into an int variable `h = f;` but I would avoid that due to a possible conversion issue. f=66.66; And.. when i write. h=f; Then .. The value of h is 66. And. I need it.. okk
5th Aug 2020, 10:48 AM
Learner
Learner - avatar
+ 3
It runs perfectly.. you can take h as 5 and the output should be 40 Try it by writing some were you may get the answer :) Ohk but when u take. Value.. 3 then f=66.67ohk And h=66; Now 66.67>66.5 So if condition ir true So out put is 66+1=67 But output is 66 why................ Solve it prblm Why.. if condition is not run.... pls explain me briefly
5th Aug 2020, 10:54 AM
Learner
Learner - avatar
+ 3
Bro... this is concept which i want 2 tell u There is no 66.67 dude The vale of f is 66 r u getting it.
5th Aug 2020, 11:23 AM
Learner
Learner - avatar
+ 3
Yes I know it.. it's a type conversation float to int..I just said the raw value of f i.e. 66.67 above :) There is mistake in this program 😁.
5th Aug 2020, 11:31 AM
Learner
Learner - avatar
+ 2
I'm not sure why you need to store a float value into an int variable `h = f;` but I would avoid that due to a possible conversion issue.
5th Aug 2020, 10:38 AM
Ipang
+ 2
The value of h is 66. And. I need it.. okk Okk ...
5th Aug 2020, 10:49 AM
Ipang
+ 2
Where is the if statement body? 5 line inside the main body and check condition also.
6th Aug 2020, 4:22 AM
Learner
Learner - avatar
+ 1
its must be c++
5th Aug 2020, 2:56 PM
Muhammad Rayyan Zishan 2006
Muhammad Rayyan Zishan 2006 - avatar
+ 1
Where is the if statement body?
6th Aug 2020, 3:12 AM
ChickenTendies
ChickenTendies - avatar