+ 2

what am i doing wrong i dont understand the message its giving or how to correct it

https://code.sololearn.com/cPuEa1Q9Vq7e/?ref=app

9th Jun 2020, 12:25 AM
Joshua Flynn
Joshua Flynn - avatar
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... }
9th Jun 2020, 10:39 AM
The Darkness
The Darkness - avatar
+ 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.
9th Jun 2020, 12:44 AM
John Robotane
John Robotane - avatar
+ 2
and you cannot multiply a string with an integer in c++, try to use a loop.
9th Jun 2020, 12:48 AM
John Robotane
John Robotane - avatar
9th Jun 2020, 11:20 AM
Ayushi Patel
Ayushi Patel - avatar
+ 1
I made the recommended changes and still confused
9th Jun 2020, 2:09 AM
Joshua Flynn
Joshua Flynn - avatar
+ 1
Joshua Flynn try this to print 'Ra' instead of using a switch statement: for (int i = 0; i< yard; i++) cout <<'Ra!';
9th Jun 2020, 3:30 AM
John Robotane
John Robotane - avatar
+ 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.
9th Jun 2020, 6:07 PM
Joshua Flynn
Joshua Flynn - avatar
+ 1
Thank you to everyone that has responded. your suggestions have been very insightful
9th Jun 2020, 6:08 PM
Joshua Flynn
Joshua Flynn - avatar
+ 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
10th Jun 2020, 1:43 AM
John Robotane
John Robotane - avatar
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.
9th Jun 2020, 8:20 PM
The Darkness
The Darkness - avatar
0
John Robotane Also a valid solution, probably more applicable to the given situation. It is still always good to experiment with other methods.
10th Jun 2020, 2:12 AM
The Darkness
The Darkness - avatar
0
how would I check to see if the input is a number
10th Jun 2020, 3:26 AM
Joshua Flynn
Joshua Flynn - avatar
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.
10th Jun 2020, 3:44 AM
The Darkness
The Darkness - avatar
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
10th Jun 2020, 3:47 AM
Joshua Flynn
Joshua Flynn - avatar
0
Did you add code to handle negative numbers?
10th Jun 2020, 4:18 AM
The Darkness
The Darkness - avatar
0
yes I have negatives covered in an if statement just before the switch
10th Jun 2020, 5:07 AM
Joshua Flynn
Joshua Flynn - avatar
0
the description is pasted in the top of the program
10th Jun 2020, 5:18 AM
Joshua Flynn
Joshua Flynn - avatar
0
lines 3 to 18
10th Jun 2020, 5:18 AM
Joshua Flynn
Joshua Flynn - avatar
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"...
10th Jun 2020, 5:22 AM
The Darkness
The Darkness - avatar
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
10th Jun 2020, 5:30 AM
Joshua Flynn
Joshua Flynn - avatar