Question
How to display a certain order of structs such as top 3 or last 3 based on user's selection in C Programming? So I'm trying
How to display a certain order of structs such as top 3 or last 3 based on user's selection in C Programming?
So I'm trying to figure out how to display the top 3 or last 3 results, in a for loop of a struct. Since it's dealing with a race, lowest number is the fastest and highest number is the slowest.
I have a struct with race results of
Struct Runner {
Char name;
Char team;
Double time;
}
Basically, the values are something like:
Name TeamTime
Emma Red 3.45
Ryan Blue4.01
Leslie Red4.23
Mike Red2.24
Milly Blue2.56
Archer Red2.54
Mela Blue4.23
John Blue3.02
Dean Blue3.23
Linda Red3.35
Then I have a switch statement that loops until the user exits
0 - Exit
1 - Display Fastest Trio of Team
2 - Display Slowest Trio of Team
3 - Display Fastest of Each Team
Choosing 1 or 2 should display a question of which team and then display the either fastest or slowest of chosen team, in which I already implemented. However, I do not know how I would display cases 1 to 3.
Output I'm trying to get:
0 - Exit
1 - Display Fastest Trio of Team
2 - Display Slowest Trio of Team
3 - Display Fastest of Each Team
User Select: 1
Which Team: Red
Fastest Trio of Team Red:
NameTime
Mike2.24
Archer2.54
Linda3.35
User Select: 2
Which Team: Blue
Slowest Trio of Team Blue:
NameTime
Dean3.23
Ryan4.01
Mela4.23
User Select: 3
Fastest Players:
NameTeamTime
MikeRed2.24
MillyBlue 2.56
User Select: 0
End
How to code for top 3 or last 3 to be displayed? Do I re-arrange the struct order each time? How would I display slowest since they're the lowest numbers but still arranged from lowest to highest when displayed? Thanks in advance
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started