Question

In: Computer Science

Write a program to take input of scores for Chemistry, Biology and English for a student...

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.

Solutions

Expert Solution

Required program in C -->

#include<stdio.h>
int main(){
int chemistry, biology, english; //declare variables chemistry,biology, and english as integer
float average; //declare variables average as float
printf("Enter chemistry marks");
scanf("%d",&chemistry); //read chemistry marks
printf("Enter biology marks");
scanf("%d",&biology); //read biology marks
printf("Enter english marks");
scanf("%d",&english); //read english marks
if(chemistry>=0&& chemistry<=100 &&biology>=0 && biology<=100 && english>=0 && english<=100){
average=(chemistry+biology+english)/3; //if in range, then calculate average
printf("%.2f",average); // print average with 2 decimal points
}
else{
if(chemistry<0 || chemistry>100){ //if chemistry not in range, print chemistry not in range
printf("Average cannot be calculated because chemistry Scores were not in range.");
}
if(biology<0 || biology>100){ //if biology not in range, print biology not in range
printf("Average cannot be calculated because Biology Scores were not in range.");
}
if(english<0 || english>100){   //if english not in range, print english not in range
printf("Average cannot be calculated because English Scores were not in range.");
}
}
  
}


Related Solutions

Using C++. Write a program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and...
Using C++. Write a program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. The input marks must be inserted one subject at a time. The program then calculate percentage and grade according to given conditions: If percentage >= 90% : Grade A If percentage >= 80% : Grade B If percentage >= 70% : Grade C If percentage >= 60% : Grade D If percentage >= 40% : Grade E If percentage < 40% : Grade...
A college offers teaching in Math, English, Chemistry, and Biology. The number of students enrolled in...
A college offers teaching in Math, English, Chemistry, and Biology. The number of students enrolled in each subject is listed below. If the college can only afford to hire 19 teachers, determine how many teachers should be assigned to each subject using Jefferson's method. (a) Subject Students Enrolled Teacher to Assign Math 370 English 265 Chemistry 105 Biology 80 (b) What modified divisor did you use?
Write a program that calculates the average of upto 100 English distances input by the user....
Write a program that calculates the average of upto 100 English distances input by the user. Create an array of objects of the Distance class, as in the ENGLARAY example in this chapter. To calculate the average, you can borrow the add_dist() member function from the ENGLCON example in Chapter 6. You’ll also need a member function that divides a Distance value by an integer. Here’s one possibility: void Distance::div_dist(Distance d2, int divisor) { float fltfeet = d2.feet + d2.inches/12.0;...
Write a program in Java that will take as input two sets A and B, and...
Write a program in Java that will take as input two sets A and B, and returns a list of all functions from A to B.
write a program that will display student grade if scores is greater than or equal to...
write a program that will display student grade if scores is greater than or equal to 70 to display A or else if score is less than or equal to 70 and greater than or equal to 60 display B if scores is less than 60 or greater than 50 display C else display fail.
Write a java program that will take a line of input and go through and print...
Write a java program that will take a line of input and go through and print out that line again with all the word numbers swapped with their corresponding numeric representations (only deal with numbers from one to nine). Sample runs might look like this: Please enter a line of input to process: My four Grandparents had five grandchildren My 4 grandparents had 5 grandchildren without array and methods.
Write a program in C++ to implement Lamport’s logical clocks. Your program should take as input...
Write a program in C++ to implement Lamport’s logical clocks. Your program should take as input a description of several process schedules (i.e., lists of send, receive or print operations). The output of your program will be a linearization of these events in the order actually performed, annotated with Lamport clock values. The input of the program will be a collection of processes, each with a list of operations to perform. The processes are named p1...pn for some n (you...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of miles, and the class of journey (1,2, or 3, for first, second, and third class respectively), for a train journey. The program should then calculate and display the fare of journey based on the following criteria: Note: Use Switch...case and if...else construct First (1) Class Second (1) Class Third (3) Class First 100 mile $ 3 per mile $ 2 per mile $ 1.50...
Sections 7.1 Write a program that reads student scores, gets the best score, and the assigns...
Sections 7.1 Write a program that reads student scores, gets the best score, and the assigns grades based on the following scheme: Grade is A if scores is >= best - 10; Grade is B if scores is >= best - 20; Grade is C if scores is >= best - 30; Grade is D if scores is >= best - 40; Grade is F otherwise. The program prompts the user to enter the total number of students, then prompts...
(JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students...
(JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students identified by rows and test scores identified by columns. Ask the user for the number of students and for the number of tests (which will be the size of the two-dimensional array). Populate the array with user input (with numbers in {0, 100} for test scores). Assume that a score >= 60 is a pass for the below. Then, write methods for: Computing the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT