How do I use the functions and strings. I can't make the average time and the invalid to work how it should. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do I use the functions and strings. I can't make the average time and the invalid to work how it should.

It's a program that allows you to enter three racing results and racers first names. The program should determine which race time was the lowest, i.e the winner. Iy should also determine if there is a tie and output the name of the winner with their time, and/or the tied individuals. In addition the program will also output the average race time. The program must check if the user enters a valid race time. A number greater than zero must be entered. If the user does not enter a valid value, display an error message and continue to ask the user to enter the value again until a valid value is entered. https://code.sololearn.com/cFKr0dXiCk6D/?ref=app

2nd Jul 2022, 7:50 PM
Zero Silver
Zero Silver - avatar
7 Answers
+ 1
Zero Silver First, why is the block between lines 60 and 124 inside 2 pairs of brackets? They don't seem nested in anything. For time input validation, I recommend an individual do..while loop for each racer time. Makes it easier and more logical for the user. Instead of testing every possible ranking combination, since you only have to output the winners, I recommend finding the shortest race time, then outputting all racers with that time. Bonus: if you create arrays instead of numbered individual variables, you can simplify your code with loops for inputs.
2nd Jul 2022, 10:18 PM
Emerson Prado
Emerson Prado - avatar
+ 1
Zero Silver what did you change, what was the intention, and what do you think about the results?
5th Jul 2022, 3:13 AM
Emerson Prado
Emerson Prado - avatar
5th Jul 2022, 2:50 AM
Zero Silver
Zero Silver - avatar
0
I changed the while loop but I can't run it on visual studios because it says the "no instance of overloaded finction 'getRaceTimes' matches the argument list" I don't know what to change about it. It also says that "raceAverage" identifier is not found, I tried to make a double but that didn't work. I tried to put it as a void but it wasn't that. I need some guidance and help, thank you.
5th Jul 2022, 5:17 PM
Zero Silver
Zero Silver - avatar
0
I have added an identifier for the raceAverage and fix the getRaceTimes to match. The code works but I got a new problem. If I put a letter in the race time input I get an infinite looping. How do I stop the looping? https://code.sololearn.com/cFKr0dXiCk6D/?ref=app
5th Jul 2022, 9:52 PM
Zero Silver
Zero Silver - avatar
0
Everytime I run the code, it spits dozens of syntax errors complaining of invalid chars from the line beginnings until first non space chars. How are you managing to run?
6th Jul 2022, 3:47 PM
Emerson Prado
Emerson Prado - avatar
0
About the infinite loop, it would help to check the int variable value after the letter input and if the buffer keeps something. But it's very hard to follow you in the dark. When changing something, make it clear what the change is, what is it for, and the results you got. Other than that, we're in a guessing game.
6th Jul 2022, 3:53 PM
Emerson Prado
Emerson Prado - avatar