There are exactly ten runners in a marathon race. | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
- 1

There are exactly ten runners in a marathon race.

There are exactly ten runners in a marathon race.Write a C++ program that prompts the user to enter the id number(of the runner) and time taken to finish the race for each of the ten runner.The program must determine both the winner of the race(the runner with the minimum time), and the second place finisher. Assume there are no ties.

28th Sep 2018, 6:52 PM
Suresh Thiyam
Suresh Thiyam - avatar
18 Réponses
+ 8
Honestly speaking, till now I have not bought/used any book. In our class, the teacher teach us from the slides that he had made. I note down the important things in my notebook. After his lecture, he gives us a task to write program for a given problem. If I get stuck somewhere, I search for the problem on the internet or ask with my teacher
29th Sep 2018, 10:20 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 7
Not much experience, 2 years till now. Keep on practicing, I bet you can write much more harder codes. Never give up, keep trying and you will get success :)
29th Sep 2018, 2:16 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 7
What's the error? it's working fine here in CPG. Btw I added into a code, there was a logical error in it. Now I have fixed it, save and run it again
29th Sep 2018, 2:37 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 7
There is a variable named totRunners, I have initialized it to 3 you can change it to 10 as per your requirement. Program will first ask you for runner ID, it is an integer then it will ask for the time, it is in float. On each iteration, you need to enter runner id and finishing time respectively
29th Sep 2018, 2:42 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 6
Show us your attempt.
28th Sep 2018, 9:33 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 6
I used different resources. First of all I started learning C++ from SoloLearn, then I started learning C and C++ at my Uni. Do searching, you'll get much information. Look at others' code, reverse engineer on their code. And keep practicing, keep making codes and if you get stuck somewhere search for it, ask on different forums. This will help you a lot in solving your problem and will also enhance your knowledge.
29th Sep 2018, 9:47 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 6
Yes gil gil you are correct, but actually I am lazy enough to read from books. :(
29th Sep 2018, 12:45 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 6
Yes gil gil you are correct, but actually I am lazy enough to read from books. :(
29th Sep 2018, 12:45 PM
blACk sh4d0w
blACk sh4d0w - avatar
29th Sep 2018, 2:01 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 2
Gil, which language you're comfortable with?
29th Sep 2018, 12:47 PM
Suresh Thiyam
Suresh Thiyam - avatar
+ 2
ok bro
29th Sep 2018, 2:30 PM
Suresh Thiyam
Suresh Thiyam - avatar
+ 2
btw , when I run the code I get 2 errors
29th Sep 2018, 2:31 PM
Suresh Thiyam
Suresh Thiyam - avatar
+ 1
Ahmad bro, where did you started learning cpp? I'm noob to cpp, this was my exam question , I don't know how to answer.
29th Sep 2018, 5:37 AM
Suresh Thiyam
Suresh Thiyam - avatar
+ 1
which books do you use?
29th Sep 2018, 9:54 AM
Suresh Thiyam
Suresh Thiyam - avatar
+ 1
Suresh Thiyam i know c# very good from school and personal experience,i learned html css and js in school but i already forgot most.now i started python. i love c# the most,python is nice too. i dont like c and c++,and i think that c# and java are the best computer languages to start with if youre completly new with programming unless you try web developing(html which is a tag language)
29th Sep 2018, 1:05 PM
gil gil
0
find the one that in the first place,change the value of the time to a very large number.then search for the first again,youll find the next
28th Sep 2018, 7:25 PM
gil gil
0
ahmed you should buy a book too and practice,anyway i dont know c++. when you try solving a problem ,before you go to the computer,draw it in a paper and solve the problem logiclly ,without any codes. for the example you gave in the question: 1.create an array of times,his length his 10 ,1 for each runner and set times for each runner. 2.declare a variable min and set it to the first value of the array of runners,also an index variable for the place of the minimum value in the array,set it to a very large number. 3.make a while loop that will check all the values in the array,and if a value is smaller then min,then min = value.so that youll get a new minimum number for the values you checked so far,set the index variable to the place in the array (index >> i). 3.set the value of arr[index] to 0.
29th Sep 2018, 12:00 PM
gil gil
0
(2) now the value of the shortest time which is the winner is 0,so if you declare a variable min2 for the second place in the marathon,and youll repeat part 2,youll get the second marathom winner because the winner's value was set to 100000, or other very big number,then when you check for the minimum nuber it wont give you the first number. this is my solution but im sure there is other easier solutions,you could use list too but im not sure how it works in c++ and if it got a min function ,good luck
29th Sep 2018, 12:03 PM
gil gil