Question

Use an array (not in vectors we didn't learn that yet, just use regular arrays) to...

Use an array (not in vectors we didn't learn that yet, just use regular arrays) to solve question 1. The code must be in C++

1a. Write a program to help me compute the average score on the quiz. Your program should prompt me to enter scores until I’m done (when I’m done I’ll enter -1). Then your program should print out the average.
1b. Build error handling into your code from 1a. If I enter a number that isn’t a valid score (the max possible is 30) or -1, reject the input and prompt me again for input. (Note: since you need to turn in both 1a and 1b, it would be easiest to start a new project and copy over your code from 1a)
1c. Modify your program from 1b so that, after I’m done entering scores, in addition to the average, it also prints out the highest and lowest scores in the class. (Note: It would be easiest to start a new project and copy over your code from 1b)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream.h>
#include<conio.h>

int main()
{
//local variables
int total=0,highest=0,lowest=0,count=0;
int score=0;
float average=0;
clrscr(); //to clear screen
//condition loop untill you have not done
while(score!=-1)
{
cout << "Enter score(From 1 to 30) or -1 when you have done: ";
cin>>score;
if(score==-1) //quit when user enter -1
break;
if(score>30)
{
cout << "Please Enter valid score ";
cin>>score;
}
if(score<=30) //valid score calculation
{
count=count+1;
total=total+score;
   if(score>highest || highest==0)
   highest=score;
   if(score<lowest || lowest==0)
   lowest=score;
}

} //end while
//calculating average score
if(count!=0)
average=(total/count); //calculation of average in integer form

cout<<endl<<" Average score : "<<average; //printing average score
cout<<endl<<" Highest score : "<<highest; //printing highest score
cout<<endl<<" Lowest score : "<<lowest; //printing lowest score


}

Add a comment
Know the answer?
Add Answer to:
Use an array (not in vectors we didn't learn that yet, just use regular arrays) to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Arrays C++ #include <iostream> using namespace std; int main() {       int   tests[6]; // array declaration...

    Arrays C++ #include <iostream> using namespace std; int main() {       int   tests[6]; // array declaration       int   sum = 0;       float avg;       //input test scores       cout << " Enter " << 6 << " test scores: " << endl;       for (int i = 0; i < 6; i++)       {             cout << "Enter Test " << i + 1 << ": ";             cin >> tests[i];       }       return 0; }    Type...

  • Program 7 Arrays: building and sorting (100 points) Due: Friday, October 30 by 11:59 PM Overview...

    Program 7 Arrays: building and sorting (100 points) Due: Friday, October 30 by 11:59 PM Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be...

  • IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are...

    IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...

  • CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes...

    CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes the user and displays the purpose of the program. It then prompts the user to enter the name of an input file (such as scores.txt). Assume the file contains the scores of the final exams; each score is preceded by a 5 characters student id. Create the input file: copy and paste the following data into a new text file named scores.txt DH232 89...

  • The purpose of this assignment is to get experience with an array, do while loop and...

    The purpose of this assignment is to get experience with an array, do while loop and read and write file operations. Your goal is to create a program that reads the exam.txt file with 10 scores. After that, the user can select from a 4 choice menu that handles the user’s choices as described in the details below. The program should display the menu until the user selects the menu option quit. The project requirements: It is an important part...

  • ***C++ Code*** What this Assignment Is About: -Learn to define and call void & non-void functions...

    ***C++ Code*** What this Assignment Is About: -Learn to define and call void & non-void functions -Learn to use reference variables Coding Guidelines for All Labs/Assignments (You will be graded on this) -Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). -Keep identifiers to a reasonably short length. -Use upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables,...

  • ASSIGNMENT #3 ** using System; namespace GradeCalculatorNew {    class MainClass    {        public...

    ASSIGNMENT #3 ** using System; namespace GradeCalculatorNew {    class MainClass    {        public static void Main (string[] args)        {            int test1,test2,test3;            double average,average2;            char letterGrade;            Console.WriteLine("Enter test score1");            test1=Convert.ToInt32(Console.ReadLine());            Console.WriteLine("Enter test score2");            test2=Convert.ToInt32(Console.ReadLine());            Console.WriteLine("Enter test score3");            test3=Convert.ToInt32(Console.ReadLine());            average=(test1+test2+test3)/3.0;            average=(int)(average+0.5);           ...

  • using Java program please copy and paste the code don't screenshot it import java.util.Scanner; import java.io.File;...

    using Java program please copy and paste the code don't screenshot it import java.util.Scanner; import java.io.File; public class { public static void main(String[] args) { // Create a new Scanner object to obtain // input from System.in // --> TODO // Ask user for a word to search for. Print // out a prompt // --> TODO // Use the Scanner object you created above to // take a word of input from the user. // --> TODO // ***...

  • NOTE: USE PYTHON CS160 Computer Science Lab 14 Working with lists, functions, and files Objective: Work...

    NOTE: USE PYTHON CS160 Computer Science Lab 14 Working with lists, functions, and files Objective: Work with lists Work with lists in functions Work with files Assignment: Part 1: Write a program to create a text file which contains a sequence of test scores. Ask for scores until the user enters an empty value. This will require you to have the scores until the user enters -1. After the scores have been entered, ask the user to enter a file...

  • Purpose: Learn to use arrays. Instructions: This is a project you will work on with a...

    Purpose: Learn to use arrays. Instructions: This is a project you will work on with a group of 3 (or 4) students. Groups of 3 will already have a left and right partner. Your assignment is to learn how to create code for others to use and how to use other people's code in your own project. Working with others is often a challenge especially when you haven't worked with them previously. If you know one of your partners from...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT