Made a program that prints out a string, depending on the amount you input in. For some reason, only the default case works. Not sure how to make it give me my exact result
You set maxScore to 100 and any of your swithc cases it is executed. Change maxScore to 95 and re-run…
It only gives me the first case. I made the declaration of the maxScore package scope also. No changes
It has nothing to do with the scope of the variable. It has to do with the value you have assigned. Try changing its value to 95 so you can see that if the first clause of your swicth is satisfied
You do the same error with every boundary. 100 is not less than 100, 90 is neither less than nor greater than 90, etc.
Yup. I should remove that maxGrade and use the parameter I passed in
Thats not what I’m talking about…
Have you tried entering
I’m meant to pass the number through the command line. So no need to declare it manually.
This works perfectly on my IDE, on the playground, doesn’t(guess that happens pretty often)
Well, the playground doesn’t allow interaction, you can’t neither specify arguments, nor can you enter something.
Just try to call your function with some sample values.
10, 65, 75, 85, 95, 70, 80, 90, 100
agreed with @Nobbz, the reason it kept failing is because it does not have any input value, thus it always hit the
I modified your source code a bit using integer slices (https://play.golang.org/p/ZnDQC1MmdXx). This way, you can test it on playground.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.