In: Computer Science
ASSIGNMENT:
Write a program to ask for the name and test score for 8 students, validate that the test score is between 0.0 and 100.0 inclusive, and store the names and test scores in 2 parallel arrays. Then, calculate and display the average of the test scores. Finally, display all the students who have test scores above the average.
Example Run #1:
(bold type is what is entered by the user)
Enter student name #1: George
Enter the score for George: 90
Enter student name #2: Sam
Enter the score for Sam: 65
Enter student name #3: Billy
Enter the score for Billy: 123
The score entered for Billy was not in the range of 0.0 to
100.0.
Please re-enter the score for Billy: 83.5
Enter student name #4: Bob
Enter the score for Bob: -5
The score entered for Bob was not in the range of 0.0 to
100.0.
Please re-enter the score for Bob: 56.7
Enter student name #5: Phil
Enter the score for Phil: 83
Enter student name #6: Scott
Enter the score for Scott: 0
Enter student name #7: Suzanne
Enter the score for Suzanne: 73.4
Enter student name #8: Joe
Enter the score for Joe: 69
The average of the scores is xx.x%.
George has a score of 90.0, which is above average.
Billy has a score of 83.5, which is above average.
Phil has a score of 83.0, which is above average.
Suzanne has a score of 73.4, which is above average.
Joe has a score of 69.0, which is above average.
The example run shows EXACTLY how your program input and output will look.
C programming NO FLOATS
** I request you to Please Provide the positive Rating**
SOURCE CODE:
#include <stdio.h>
int main()
{
int n=8,i,sum=0;
char names[10][8];
int scores[10];
float avgscore;
for (int i=0; i<n;i++)
{
printf("\n enter the student name:\n ");
scanf(" %s",names+i);
printf("\n enter the score:");
scanf("%d",&scores[i]);
sum=sum+scores[i];
}
avgscore=sum/n;
printf("\n The average of the scores is %f \n",avgscore);
for(i=0;i<n;i++)
{
if(scores[i]>avgscore)
{
printf("\n%s has a score %d which is above average\n ", names+i,
scores[i]);
}
}
return 0;
}
OUTPUT:
enter the student name:
george
enter the score:56
enter the student name:
joe
enter the score:47
enter the student name:
pinky
enter the score:98
enter the student name:
sanju
enter the score:23
enter the student name:
sushu
enter the score:75
enter the student name:
wicky
enter the score:46
enter the student name:
shriya
enter the score:65
enter the student name:
shannu
enter the score:12
The average of the scores is 52.000000
george has a score 56 which is above average
pinky has a score 98 which is above average
sushu has a score 75 which is above average
shriya has a score 65 which is above average