Question

In: Computer Science

Write an application that allows a user to enter any number of student quiz scores, as...

Write an application that allows a user to enter any number of student quiz scores, as integers, until the user enters 99. If the score entered is less than 0 or more than 10, display Score must be between 10 and 0 and do not use the score. After all the scores have been entered, display the number of valid scores entered, the highest score, the lowest score, and the arithmetic average.

Solutions

Expert Solution

python:

Code:

#count to store the number of valid inputs
count=0
#highdcore
highscore=-1
#low score
lowscore=100
#variable to store sum
s=0
#an infinite loop which only breaks when 99 is entered
while(True):
   #taking input
   num=int(input("Enter Quiz score "))
   #checking if it is 99
   if(num == 99):
       break
   #if it is not between 0 and 10
   if(num<0 or num>10):
       print("Score must be between 10 and 0")
       #starting again from the loop
       continue
   #incrementing count
   count=count+1
   #adding num to sum
   s=s+num
   #getting highscore
   if(highscore<num):
       highscore=num
   #getting lowscore
   if(lowscore>num):
       lowscore=num
#finding average
avg=s/count
#printing results
print("Average is "+str(avg))
print("Highest score is "+str(highscore))
print("Lowest score is "+str(lowscore))
print("Count is "+str(count))

Output:

Code Screenshot:

Code Snippet:

#count to store the number of valid inputs
count=0
#highdcore
highscore=-1
#low score
lowscore=100
#variable to store sum
s=0
#an infinite loop which only breaks when 99 is entered
while(True):
        #taking input
        num=int(input("Enter Quiz score "))
        #checking if it is 99
        if(num == 99):
                break
        #if it is not between 0 and 10
        if(num<0 or num>10):
                print("Score must be between 10 and 0")
                #starting again from the loop
                continue
        #incrementing count
        count=count+1
        #adding num to sum
        s=s+num
        #getting highscore
        if(highscore<num):
                highscore=num
        #getting lowscore
        if(lowscore>num):
                lowscore=num
#finding average
avg=s/count
#printing results
print("Average is "+str(avg))
print("Highest score is "+str(highscore))
print("Lowest score is "+str(lowscore))
print("Count is "+str(count))

java:

code:

//importing this package as we are using Scanner class
import java.util.*;
//class name is Quiz score so, file should be saved as QuizScore.java
class QuizScore{
   //main method
   public static void main(String[] args) {
       Scanner s = new Scanner(System.in);
       //declaring variables
       int count=0;
       int high=-1;
       int low=100;
       int sum=0;
       float avg;
       int num;
       //an infinite loop which onl breaks when 99 is entered
       while(true){
           //taking input
           System.out.println("Enter Quiz Score");
           num=s.nextInt();
           //checking if it is 99
           if(num==99){
               //if 99 is entered break
               break;
           }
           //checking if the number is not between 10 and 0 or not
           if(num<0 || num>10){
               //if it is not then starting loop again
               System.out.println("Score must be between 10 and 0");
               continue;
           }
           //incrementing count
           count++;
           //adding num to sum
           sum=sum+num;
           //finding highest and lowest
           if(high<num){
               high=num;
           }
           if(low>num){
               low=num;
           }


       }
       //finding average and printing results
       avg=sum/count;
       System.out.println("Average is "+avg);
       System.out.println("Highest score is "+high);
       System.out.println("Lowest score is "+low);
       System.out.println("Count is "+count);
   }
}

Output:

Code Screenshot:

Code Snippet:

//importing this package as we are using Scanner class
import java.util.*;
//class name is Quiz score so, file should be saved as QuizScore.java
class QuizScore{
        //main method
        public static void main(String[] args) {
                Scanner s = new Scanner(System.in);
                //declaring variables
                int count=0;
                int high=-1;
                int low=100;
                int sum=0;
                float avg;
                int num;
                //an infinite loop which onl breaks when 99 is entered
                while(true){
                        //taking input
                        System.out.println("Enter Quiz Score");
                        num=s.nextInt();
                        //checking if it is 99
                        if(num==99){
                                //if 99 is entered break
                                break;
                        }
                        //checking if the number is not between 10 and 0 or not
                        if(num<0 || num>10){
                                //if it is not then starting loop again
                                System.out.println("Score must be between 10 and 0");
                                continue;
                        }
                        //incrementing count
                        count++;
                        //adding num to sum
                        sum=sum+num;
                        //finding highest and lowest
                        if(high<num){
                                high=num;
                        }
                        if(low>num){
                                low=num;
                        }


                }
                //finding average and printing results
                avg=sum/count;
                System.out.println("Average is "+avg);
                System.out.println("Highest score is "+high);
                System.out.println("Lowest score is "+low);
                System.out.println("Count is "+count);
        }
}

C:

Code:

#include<stdio.h>
//main function
int main(){
   //declaring and initializing variables
   int count=0;
   int high=-1;
   int low=100;
   int sum=0;
   int num;
   //an infinite loop which only breaks when 99 is entered
   while(1){
       //takng user input
       printf("Enter Quiz score: ");
       scanf(" %d",&num);
       //if num is 99 loop terminates
       if(num==99){
           break;
       }
       //if num is not between 0 and 10 loop starts again
       if(num<0 || num>10){
           printf("Score must be between 10 and 0\n");
           continue;
       }
       //increment count
       count++;
       //adding num to sum
       sum=sum+num;
       //finding highest and lowest
       if(high<num){
           high=num;
       }
       if(low>num){
           low=num;
       }
      
   }
   //finding average
   float avg=sum/count;
   //printing results
   printf("Average is %.2f\n",avg);
   printf("Highest score is %d\n",high);
   printf("Lowest Score is %d\n",low);
   printf("The count is %d",count);
}

Output:

Code Screenshot:

Code Snippet:

#include<stdio.h>
//main function
int main(){
        //declaring and initializing variables
        int count=0;
        int high=-1;
        int low=100;
        int sum=0;
        int num;
        //an infinite loop which only breaks when 99 is entered
        while(1){
                //takng user input
                printf("Enter Quiz score: ");
                scanf(" %d",&num);
                //if num is 99 loop terminates
                if(num==99){
                        break;
                }
                //if num is not between 0 and 10 loop starts again
                if(num<0 || num>10){
                        printf("Score must be between 10 and 0\n");
                        continue;
                }
                //increment count
                count++;
                //adding num to sum
                sum=sum+num;
                //finding highest and lowest
                if(high<num){
                        high=num;
                }
                if(low>num){
                        low=num;
                }
                
        }
        //finding average
        float avg=sum/count;
        //printing results
        printf("Average is %.2f\n",avg);
        printf("Highest score is %d\n",high);
        printf("Lowest Score is %d\n",low);
        printf("The count is %d",count);
}

Related Solutions

Write an application that allows a user to enter any number of student quiz scores until...
Write an application that allows a user to enter any number of student quiz scores until the user enters 99. If the score entered is less than 0 or more than 10, display an appropriate message and do not use the score. After all the scores have been entered, display the number of scores entered, the highest score, the lowest score, and the arithmetic average. Save the file as QuizScoreStatistics.java. I am struggling with looping in Java and do not...
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...
Show: Create an application that allows the user to enter the number of calories and fat...
Show: Create an application that allows the user to enter the number of calories and fat grams in a food. The application should display the percentage of the calories that come from fat. If the calories from fat are less than 30% of the total calories of the food, it should also display a message indicating the food is low in fat. One gram of fat has 9 calories, so: Calories from fat = fat grams *9 The percentage of...
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm Explain step by step
Create an application that allows the user to enter the total for an order and the...
Create an application that allows the user to enter the total for an order and the name of the customer. If the order is less than 500 dollars, the customer gets no discount. If the order is greater than or equal to 500 and less than 1000 dollars, the customer gets a 5 percent discount. If the order is greater than or equal to 1000 dollars, the customer gets a 10 percent discount. The application should display the name of...
Write a C++ console application that allows your user to enter the total rainfall for each...
Write a C++ console application that allows your user to enter the total rainfall for each of 12 months into an array of doubles. The program should validate user input by guarding against rainfall values that are less than zero. After all 12 entries have been made, the program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest rainfall amounts.
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
Using Visual Studio write a program that allows the user to enter multiple scores ranging from...
Using Visual Studio write a program that allows the user to enter multiple scores ranging from 0 to 100, computes the average of those scores and then writes out a letter grade using the typical grading scale. Your program will also: 1. Allow the user to enter any number of scores he or she wishes but assume there will be at least one score entered. 2. Use a sentinel-controlled loop variable to terminate the loop when the user has no...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT