OpenStudy (anonymous):

Anyone can help with this program ? Write a program that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and third place. Think about how many test cases are needed to verify that your program works correctly. (That is, how may different finish orders are possible?)

5 years ago
OpenStudy (espex):

What language?

5 years ago
OpenStudy (anonymous):

C++

5 years ago
OpenStudy (anonymous):

So far I have int main() { string name; cout << "Enter name of runner number 1: " << endl; getline(cin, name); cout << "Enter name of runner number 2: " << endl; getline(cin, name); cout << "Enter name of runner number 3: " << endl; getline(cin, name);

5 years ago
OpenStudy (espex):

You will need to create three variables for name as well as time, or a struct, or array. As you have it now the "name" will be overwritten each time the user inputs a name.

5 years ago
OpenStudy (anonymous):

I was talking with my instructor, he was like it's right you just need the if/else statement. After trying it for few times, I just got tired of it and don't know what I'm doing wrong that making the program not running !!

5 years ago
OpenStudy (espex):

Well start off with a single case, have it ask the user for a name, a time, and then print the name and time back to the user. Once that is working you can simply copy/paste that code 3 times, simply add a number to the 'name' and 'time', so name1/time1, name2/time2, name3/time3 and get it to print all of them to the screen. At that point half of the work will be done and the last matter is sorting them in order, which is the if/else statement.

5 years ago
OpenStudy (anonymous):

Ok I will try it tomorrow since my brain can't see this program anymore :/ Thank you eSpex for your help. Highly appreicated =)

5 years ago
OpenStudy (espex):

heh, understood. :)

5 years ago
OpenStudy (ajprincess):

5 years ago
OpenStudy (farmdawgnation):

ajprincess, under no circumstances should you provide the solution when someone else is already helping with this question. This is blatantly against the Code of Conduct.

5 years ago
OpenStudy (anonymous):

ajprincess ! Thank you so much for your help; However, the program didn't run. I will try to figure it out

5 years ago
OpenStudy (ajprincess):

am so sorry @farmdawgnation I didn't knw that. Wil not repeat the same mistake again.

5 years ago
OpenStudy (ajprincess):

@Dode1986 it works k in devC++

5 years ago
OpenStudy (anonymous):

I have visual studio, after I will figure it out I will send it to you :) Thanks again

5 years ago
OpenStudy (ajprincess):

yw.

5 years ago
OpenStudy (espex):

The C environment shouldn't make a big difference as code appears to be correct. I would work a little on the logic however. I would suggest you take the example that @ajprincess offered and step through each statement line by line. Pick three numbers, let's say 2, 9, 6, and start with the first 'if' statement and write out exactly what is happening each line then it will become more clear.

5 years ago
OpenStudy (ajprincess):

@eSpex vat alterations should I make in my coding to make it 100% perfect.

5 years ago
OpenStudy (espex):

@ajprincess I would make the following adjustments: http://pastebin.com/XSEvciLu

5 years ago
OpenStudy (espex):

New url, I missed a brace in the last one. http://pastebin.com/skrffWHJ

5 years ago
OpenStudy (ajprincess):

Thanks a lot.

5 years ago
OpenStudy (espex):

You're welcome.

5 years ago
OpenStudy (anonymous):

@ eSpeX and ajprincess thank you guys for your help ! It's still driving me crazy though and my class-mates. Keeps giving erros. I tried on visual studio and codemate, it doesn't work on both. The error is giving doesn't make any sence cause the line is after the return 0; } ---> error Source Line Line Number 58 Compiler Error parse error at end of input

5 years ago
OpenStudy (espex):

I compiled and ran this code in visual studio and it works as expected. The one addition I did notice was the inclusion of string was missing. However once I added that #include everything worked. If this still gives you an error I would be very interested in seeing exactly what the compiler spat out. http://pastebin.com/acgtMzjR

5 years ago
OpenStudy (anonymous):

I will run it and send you the picture for the error I'm having, again not only me but my class-mates as well (different computers and different programs). However, I emailed my instructor and he said he will try to run it himself and let me know. I haven't received anything from him yet.

5 years ago
OpenStudy (anonymous):

Like there is nothing in line 58 or whatever line comes after * } * Also, on visual studio it's not giving an error, but just telling me that it's not recognized ! which is worse, at least with the erro I can tell what I'm missing..lol anyway, don't bother yourself. I appreicate your time =)

5 years ago
OpenStudy (espex):

In visual studio you should ensure that you have #include <string> as the error is similar to what I was getting the first time I ran it.

5 years ago
OpenStudy (anonymous):

I do have it !

5 years ago
OpenStudy (espex):

Comment out the system call at the end of the program and try it again. http://codepad.org/ijYOOFIb

5 years ago
OpenStudy (espex):

This one even let me add input. http://ideone.com/4M5g0 Unfortunately I cannot use the same tool you are using as I am not in your class. Hopefully your instructor will get back to you with good news soon.

5 years ago
OpenStudy (anonymous):

Hopefully and I will let you know :)

5 years ago
OpenStudy (espex):

For what it is worth, if you'd like to see it in action check out the "upload with new input" at the bottom of this page: http://ideone.com/4M5g0

5 years ago
Similar Questions: