+ 2
what am i doing wrong i dont understand the message its giving or how to correct it
22 Réponses
+ 1
In the line where you input yards, remove endl from the end of the input.
endl is for when using cout.
In switch statement, remove comparison operators and leave as case 0: case 1: etc. Since we are switching on yards the switch statement handles comparison for us, however the variable must be discrete, otherwise no < or >.
In cout statements remove commas and insert semicolons.
Make sure entire switch statement is in { } e.g. switch (yards){
case 0:
cout << "shh";
break;
case 1:
Etc...
}
+ 4
1. you should not print something you are not asked to print. so you must remove the line 21.
2. you must respect the message case: print 'Ra' rather than 'ra' and 'High Five' instead of 'high five'.
3. the value of 'output' should be printed, not returned.
+ 2
and you cannot multiply a string with an integer in c++, try to use a loop.
+ 1
I made the recommended changes and still confused
+ 1
Joshua Flynn try this to print 'Ra' instead of using a switch statement:
for (int i = 0; i< yard; i++)
cout <<'Ra!';
+ 1
I implemented your suggestions, and it works except it fails 2 of the 5 test cases. Unless those test cases are negative numbers, shouldn't it pass all of them? It is not showing anything about the two failed tests.
+ 1
Thank you to everyone that has responded. your suggestions have been very insightful
+ 1
sorry I was offline. what I wanted you to do was to use a loop rather than a switch statement. so your code should look like this :
https://code.sololearn.com/c962Uo2KByco/?ref=app
0
Joshua Flynn
In order to handle negative numbers, a check should probably be done on the input and then set the yards to 0.
if (yards < 0)
yards = 0;
Switch (yards){
}
If the yards data needs to be preserved for calculations, then a placeholder variable might have to be used and then switched upon.
0
John Robotane
Also a valid solution, probably more applicable to the given situation.
It is still always good to experiment with other methods.
0
how would I check to see if the input is a number
0
You could use isdigit() however you would likely have to iterate over the entire string and check each index.
With cin, it appears that the type is already inferred before it is stored in the variable. It is still a good idea to check the input before trying to store it.
0
but looking at the challenges parameters I think they are only sending numbers so which has me confused as to what the twst is that it failed
0
Did you add code to handle negative numbers?
0
yes I have negatives covered in an if statement just before the switch
0
the description is pasted in the top of the program
0
lines 3 to 18
0
Oops missed that. That's what I get for reading code not comments.
It looks like you may need a case for 10. "If they move forward 10 or less yards"...
0
one reason I stayed with the switch instead of using the loop he mentioned was that I want as much of the code as possible to be written by me but I placed his method as a comment at the bottom of the page to assist in learning other ways of doing things