Skip to content
← Back to Community
Student Line Up
Profile icon
Gooftroop21

A teacher has asked all her students to line up single file according to their first name. For
example, in one class Amy will be at the front of the line and Yolanda will be at the end. Write a
program that prompts the user to enter the number of students in the class, then loops to read
that many names. Once all the names have been read it reports which student would be at the
front of the line and which one would be at the end of the line. You may assume that no two
students have the same name.

Input Validation: Do not accept a number less than 1 or greater than 25 for the number of
students.

I'm code isn't running correctly and I'm not sure why.

Voters
Profile icon
Gooftroop21
Comments
hotnewtop
Profile icon
mwilki7

for (counter = 0;...
and
if (counter == 1)

It always overwrites the first name because the if statement tells it to.
If you want to fix it, change:
if (counter == 1)
to
if (counter == 0)

Profile icon
Gooftroop21

@mwilki7 Oh my gosh, thank you so much!

Profile icon
NeelYang

Hello! I might want to suggest the essay writing service https://www.collegessaywriter.com/write-my-speech/ - this is a cool online assistance where you can purchase essays on your point, of any intricacy. I frequently reach them to save my time.