Question

In: Computer Science

Write a C program that allows users to enter three runners name (up to 20 characters)...

Write a C program that allows users to enter three runners name (up to 20 characters) and their runtime (2 decimals)

(1) First and Last name

(2) Running time for 100 m ex. 9.96 seconds

your program should rank them in ascending order of their runtime. example:

usian Bolt - 9.96 sec - First Place

John doe - 9.99 sec - second Place

Pete Urel -10.11 sec - third place

BUT they fan tie for first place and no second place awarded

usian Bolt - 9.96 sec - First Place

John doe - 9.96 sec -First Place

Pete Urel -10.11 sec - third place

OR they can tie for second place and no third place awarded

usian Bolt - 9.96 sec - First Place

John doe - 10.11sec - second Place

Pete Urel -10.11 sec - second place

YOU CANNOT USE AN ARRAY DATA STRUCTURE TO STORE DATA FOR EACH RUNNER

Solutions

Expert Solution

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
char fname1[20],fname2[20],fname3[20],lname1[20],lname2[20],lname3[20];
float time1,time2,time3;
int first,second,third;
clrscr();
printf("\n enter the first and last name of first runner and running time ");
scanf("%s%s%f",fname1,lname1,&time1);
fflush(stdin);
printf("\n enter the first and last name of second runner and running time ");
scanf("%s%s%f",fname2,lname2,&time2);
fflush(stdin);
printf("\n enter the first and last name of third runner and running time ");
scanf("%s%s%f",fname3,lname3,&time3);
fflush(stdin);
if(time1>time2&&time1>time3&&time2!=time3)
{
first=time1;
printf("%s %s %0.2f sec - First Place",fname1,lname1,time1);
if(time2>time3)
{
second=time2;
printf("\n %s %s %0.2fsec - Second Place",fname2,lname2,time2);
third=time3;
printf("\n %s %s %0.2fsec - Thirs Place",fname3,lname3,time3);
}
else
{
second=time3;
printf("\n %s %s %0.2f sec - Second Place",fname3,lname3,time3);
third=time1;
printf("\n %s %s %0.2f sec - Third Place",fname2,lname2,time2);
}
}

else if(time2>time3&&time2>time1&&time3!=time1)
{
first=time2;
printf("\n %s %s %0.2f sec - First Place",fname2,lname2,time2);
if(time3>time1)
{
second=time3;
printf("\n %s %s %0.2f sec - Second Place",fname3,lname3,time3);
third=time1;
printf("\n %s %s %0.2f sec - Third Place",fname1,lname1,time1);
}
else
{
second=time1;
printf("\n %s %s %0.2f sec - Second Place",fname1,lname1,time1);
third=time3;
printf("\n %s %s %0.2f sec - Third Place",fname3,lname3,time3);
}
}
else if(time3>time1&&time3>time2&&time1!=time2)
{
first=time3;
printf("\n %s %s %0.2f sec - First Place",fname3,lname3,time3);
if(time1>time2)
{
second=time1;
printf("\n %s %s %0.2f sec - Second Place",fname1,lname1,time1);
third=time2;
printf("\n %s %s %0.2f sec - Third Place",fname2,lname2,time2);
}
else
{
second=time2;
printf("\n %s %s %0.2f sec - Second Place",fname2,lname2,time2);
third=time1;
printf("\n %s %s %0.2f sec - Third Place",fname1,lname1,time1);
}
}
else if(time1==time2)
{
if(time1<time3)
{
printf("\n %s %s %0.2f sec - First Place",fname1,lname1,time1);
printf("\n %s %s %0.2f sec - First Place",fname2,lname2,time2);
printf("\n %s %s %0.2f sec = Third Place",fname3,lname3,time3);
}
else
{
printf("\n %s %s %0.2f sec - First Place",fname3,lname3,time3);
printf("\n %s %s %0.2f sec - Second Place",fname1,lname1,time1);
printf("\n %s %s %0.2f sec = Second Place",fname2,lname2,time2);

}
}
else if(time2==time3)
{
if(time2<time1)
{
printf("\n %s %s %0.2f sec - First Place",fname2,lname2,time2);
printf("\n %s %s %0.2f sec - Frist Place",fname3,lname3,time3);
printf("\n %s %s %0.2f sec - Third place",fname1,lname1,time1);
}
else
{
printf("\n %s %s %0.2f sec - First Place",fname1,lname1,time1);
printf("\n %s %s %0.2f sec - Second Place",fname2,lname2,time2);
printf("\n %s %s %0.2f sec - Second Place",fname3,lname3,time3);

}
}
else
{
if(time3<time2)
{
printf("\n %s %s %f sec - First Place",fname1,lname1,time1);
printf("\n %s %s %f sec - First Place",fname3,lname3,time3);
printf("\n %s %s %f sec - Third Place",fname2,lname2,time2);
}
else
{
printf("\n %s %s %f sec - First Place",fname2,lname2,time2);
printf("\n %s %s %f sec - Second Place",fname1,lname1,time1);
printf("\n %s %s %f sec - Second Place",fname3,lname3,time3);

}

}

}

Sample Run1:

Sample Run2:

Sample Run3:


Related Solutions

Program must be in C Write a program that allows the user to enter the last...
Program must be in C Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate in two different arrays. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. Example (Letters and numbers with underscore indicate an input):...
write this program in C++ Write a program that prompts a user for three characters. The...
write this program in C++ Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value. Example 1: Input : 10 Input : 20 Input : 30 The largest is 30. The lowest is 10. Example 2: Input : 100 Input : 50 Input :...
Write a C program that prompts the user to enter some information about up to 20...
Write a C program that prompts the user to enter some information about up to 20 individuals (think of a way to welcome and prompt the user). It must be stored in a structure. Once data is entered, the program output it as shown in sample run below. Your program should include a structure with a tag name of: “information”. It should contain the following data as members: a struct to store employee's name, defined as: struct name fullname e.g....
Write a C program that prompts the user to enter some information about up to 20...
Write a C program that prompts the user to enter some information about up to 20 individuals (think of a way to welcome and prompt the user). It must be stored in a structure. Once data is entered, the program output it as shown in sample run below. Your program should include a structure with a tag name of: “information”. It should contain the following data as members: a struct to store employee's name, defined as: struct name fullname e.g....
C++ Vector Write a program that allows the user to enter the last names of the...
C++ Vector Write a program that allows the user to enter the last names of the candidates in a local election and the votes received by each candidate. The program should then output each candidate's name, votes received by that candidate, and the percentage of the total votes received by the candidate. Assume a user enters a candidate's name more than once and assume that two or more candidates receive the same number of votes. Your program should output the...
In C++, write a program that will read up to 10 letters (characters) into an array...
In C++, write a program that will read up to 10 letters (characters) into an array and write the letters back to the screen in the reverse order. The program should prompt the user to input all values and can determine whether the input has ended by a punctuation mark such as ‘.’ (make sure that you’ll include meaningful and intuitive messages to the user). For example, if the input is abcde, the output should be edcba. Include appropriate messaging...
Write a C++ program that will require users to enter an automobile VIN number and you...
Write a C++ program that will require users to enter an automobile VIN number and you will check certain aspects: The VIN number must be 17 characters exactly in length The VIN number may contain only letters and numbers The first character is the location of manufacture; we will check for this to be 1 to 5 (made in North America). The 10th character indicates the manufacture year. We will check for this being a letter between A and I...
DATA STRUCTURES USING C++ 2ND EDITION Write a program that allows the user to enter the...
DATA STRUCTURES USING C++ 2ND EDITION Write a program that allows the user to enter the last names of five candidates in a local election and the votes received by that candidate. The program should then output each candidates name, votes received by that candidate, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is as follow Johnson    5000 25.91 miller    4000   ...
Write a C++ program using dynamic arrays that allows the user to enter the last names...
Write a C++ program using dynamic arrays that allows the user to enter the last names of the candidates in a local election and the number of votes received by each candidate. The program must ask the user for the number of candidates and then create the appropriate arrays to hold the data. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should...
Write an application that allows a user to enter the names and birthdates of up to...
Write an application that allows a user to enter the names and birthdates of up to 10 friends. Continue to prompt the user for names and birthdates until the user enters the sentinel value ZZZ for a name or has entered 10 names, whichever comes first. When the user is finished entering names, produce a count of how many names were entered, and then display the names. In a loop, continuously ask the user to type one of the names...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT