What /where is the bug🧐 | SoloLearn: Learn to code for FREE!

+2

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; }

3/3/2021 4:14:14 PM

Noname

10 Answers

New Answer

+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!!

+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.

+1

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 }

+1

Simba thank u

+1

Noname what output are you expecting? The code runs without errors, so 'the bug' depends solely on your expectation. Do you really want it to print "High Five" thousand times without line break when yard==1000? Is it ok for it to do nothing when yard<1, rather than to output "ssh"? It's up to you.

+1

Simba ok bro , I will . I didn't understand how it works. Thanks a lot

0

electron Int yard = 0; If (yard<1) .....//0<1 U said that won't work Or?

0

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

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 👌

0

Vishnuvasan Srinivasan u're genius !!!!!!!!!!!