Program specifications:
Declare an array to store up to 10 integer percentage values.
Ask the user to input 10 percentages (range 0–100).Verify that the input is valid.Note that only valid (0–100)percentages.
If the user enters an invalid percentage:display an error message and do not store or process the invalid value.After the error message,prompt for the next input.
Once all 10 valid percentages are entered, calculate the average percentage and display it.
Calculate and display the highest and lowest percentage obtained.
Then display all percentages that are equal to or more than the average.
Lastly,display all 10 values entered by the user together with their letter grade values,one percentage and letter grade per line.
Determine the letter grade based on test percentage
TEST PERCENTAGE GRADE
From 80 to 100 ‘A’
From 70 to 79 ‘B’
From 60 to 69 ‘C’
From 50 to 59 ‘D’
0-49 'F'
#include <stdio.h>
int main()
{
int arr[10];
printf("Enter 10 percentage values between 0 and 100: ");
int i=0;
while(i<10){
scanf("%d",&arr[i]);
if (arr[i]<0 || arr[i]>100)
printf("Invalid percentage");
continue;
}
int sum=0;
for(int i=0;i<10;i++){
sum=sum+arr[i];
}
int avg=sum/10;
printf("Average: %d",avg);
int min=arr[0];
int max=arr[0];
for(int i=0;i<10;i++){
if (arr[i]<min)
min=arr[i];
}
for(int i=0;i<10;i++){
if (arr[i]>max)
max=arr[i];
}
printf("\nSmallest percentage is %d\n",min);
printf("\nLargest percentage is %d\n",max);
char grade;
if (avg>=80 && avg<=100)
grade='A';
else if (avg>=70 && avg<=79)
grade='B';
else if (avg>=60 && avg<=69)
grade='C';
else if (avg>=50 && avg<=59)
grade='D';
else if (avg>=0 && avg<=49)
grade='F';
printf("Grade: %c",grade);
return 0;
}
Comments
Leave a comment