In: Computer Science
THIS IS FOR DEVC++. I use the 5.11 version
Write a program to take input of scores for Chemistry, Biology and English for a student and display the average with 2 decimal places if all of the three scores are in the range between 1 and 100 inclusive. Program should also display the course name for which scores are entered out of range telling Average couldn't be calculated.
Following is a sample run:
Enter scores for Chemistry, Biology and English between 1 and
100:
45
89
96
Avg score is 76.67
Following is another sample run:
Enter scores for Chemistry, Biology and English between 1 and
100:
900
78
89
Average cannot be calculated because Chemistry Scores were not in
range.
Following is another sample run:
Enter scores for Chemistry, Biology and English between 1 and
100:
89
767
8787
Average cannot be calculated because Biology Scores were not in
range.
Average cannot be calculated because English Scores were not in
range.
Following is another sample run:
Enter scores for Chemistry, Biology and English between 1 and
100:
87
90
-1
Average cannot be calculated because English Scores were not in
range.
Answer-
your code is here-
#include <stdio.h>
int main()
{
float chm, bio, eng;
float total, average;
printf("Enter scores for Chemistry, Biology and English between 1
and 100:\n");
scanf("%f%f%f", &chm,&bio, &eng);
if(chm<1 || chm>100 )
{
printf("Average cannot be calculated because Chemistry
Scores were not in range.\n");
}
if(bio<1 || bio>100 )
{
printf("Average cannot be calculated because Biology
Scores were not in range.\n");
}
if(eng<1 || eng>100 )
{
printf("Average cannot be calculated because English
Scores were not in range.\n");
}
if(chm>=1 && chm<=100 && bio>=1 &&
bio<=100 && eng>=1 && eng<=100 )
{
total = eng + bio + chm ;
average = total / 3.0;
printf("Avg score is = %.2f\n", average);
}
return 0;
}
some screenshot of running output as your requirement-
Note- Please do upvote, if any problem then comment in
box sure I will help.