Ask your own question, for FREE!
Computer Science 64 Online
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?)

OpenStudy (espex):

What language?

OpenStudy (anonymous):

C++

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);

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.

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 !!

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.

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 =)

OpenStudy (espex):

heh, understood. :)

OpenStudy (ajprincess):

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.

OpenStudy (anonymous):

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

OpenStudy (ajprincess):

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

OpenStudy (ajprincess):

@Dode1986 it works k in devC++

OpenStudy (anonymous):

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

OpenStudy (ajprincess):

yw.

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.

OpenStudy (ajprincess):

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

OpenStudy (espex):

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

OpenStudy (espex):

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

OpenStudy (ajprincess):

Thanks a lot.

OpenStudy (espex):

You're welcome.

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

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

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.

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 =)

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.

OpenStudy (anonymous):

I do have it !

OpenStudy (espex):

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

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.

OpenStudy (anonymous):

Hopefully and I will let you know :)

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

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Arianna676: should i block everybody on my list?
53 seconds ago 9 Replies 2 Medals
Arianna676: i am not taking for break?
52 minutes ago 4 Replies 0 Medals
uknownprttyfacekayla: I drew this not sure what i was aiming for but i just drew what my heart guided m
5 minutes ago 6 Replies 3 Medals
alphaXtiger: what is the meaning of math meaning who made it.
1 hour ago 3 Replies 3 Medals
axie: Poem I think
1 hour ago 13 Replies 3 Medals
Fz150: what is the definition of art?
2 hours ago 2 Replies 2 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!