What /where is the bug🧐 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What /where is the bug🧐

#include <stdio.h> int main() { int yard; int i; scanf("%d",&yard); for (i=0;i<yard;i++){ if (yard>10) printf ("%s","High Five"); if (yard<=10 && yard>=1) printf ("%s","Ra!"); if (yard<1) printf ("%s", "ssh"); } return 0; }

3rd Mar 2021, 4:14 PM
Noname
Noname - avatar
9 Answers
+ 3
Bro the code is absolutely fine!!! The only MISTAKE is in the printf stmt followed by the three if's. Remove the <"%s",> from all the printf's. If removed, the code will run without throwing bugs. '%s' is used to output a string and the prerequisite is that the string should be stored in a variable. For example: char c[50] = "BUG"; //a1 printf("%s",c); //a2 -------(OR)------ printf("BUG"); //b In the above example both a and b prints BUG as o/p. But look at the difference. U r storing the value in a variable and throwing o/p through that variable in a1,a2. Whereas in b, we are directly printing BUG. And these cannot be clubbed together which will cause errors as of in ur case!!! Hope u understood!!
4th Mar 2021, 4:19 AM
Vishnuvasan Srinivasan
Vishnuvasan Srinivasan - avatar
+ 5
You have to use the for loop when 1< yard <=10 only. For other conditions, you can get the output without using the loop. electron because 👀 https://www.sololearn.com/coach/20?ref=app Noname glad to hear that you completed the challenge. Next time, you can attach the task in description to understand your question clearly.
3rd Mar 2021, 4:49 PM
Simba
Simba - avatar
+ 2
The third "if" can't work because if "yard" is less than 1 then in "for" loop statement is "false": int yard =0; for(int i =0; i< yard; i++){ //the body can't be executed }
3rd Mar 2021, 4:45 PM
electron
electron - avatar
+ 1
Simba thank u
3rd Mar 2021, 5:19 PM
Noname
Noname - avatar
+ 1
Noname yes because you have used the "yard" variable also as a condition in the for loop Simba I have read your comment 3 times and now I understood 😅. My english is too sucks. Anyway I think the same about the challenge
3rd Mar 2021, 8:22 PM
electron
electron - avatar
+ 1
Simba ok bro , I will . I didn't understand how it works. Thanks a lot
4th Mar 2021, 8:41 AM
Noname
Noname - avatar
0
electron Int yard = 0; If (yard<1) .....//0<1 U said that won't work Or?
3rd Mar 2021, 5:22 PM
Noname
Noname - avatar
0
C-MOON yard was given as input. If yard > 10 it will be printed "high five " one how matter the yard , but if yard >1 && yard <10 it will be printed "Ra!" until I==yard. But I have solved it, I made one mistake with "ssh <> "shh __ that's why I had a bug. Thank you 👌
4th Mar 2021, 12:15 AM
Noname
Noname - avatar
0
Vishnuvasan Srinivasan u're genius !!!!!!!!!!!
4th Mar 2021, 8:39 AM
Noname
Noname - avatar