Question

// This program will read in a group of test scores (positive integers from 1 to...

// This program will read in a group of test scores (positive integers from 1 to 100)
// from the keyboard and then calculate and output the average score
// as well as the highest and lowest score. There will be a maximum of 100 scores.

//

#include <iostream>
using namespace std;

float findAverage (const int[], int); // finds average of all grades
int findHighest (const int[], int); // finds highest of all grades
int findLowest (const int[], int); // finds lowest of all grades

int main()
{
   int grades[100]; // the array holding the grades.
   int numberOfGrades; // the number of grades read.
   int pos = 0; // index to the array.
   float avgOfGrades; // contains the average of the grades.
   int highestGrade; // contains the highest grade.
   int lowestGrade; // contains the lowest grade.

   // Read in the values into the array pos = 0;
   cout << "Please input a grade from 1 to 100, (or -99 to stop)" << endl;
   cin >> grades[pos];

   while (grades[pos] != -99)
   {
       cin >> grades[pos];
   }

   numberOfGrades = grades[pos]; // Fill blank with appropriate identifier
   // call to the function to find average

   avgOfGrades = findAverage(grades, numberOfGrades);
   cout << endl << "The average of all the grades is " << avgOfGrades << endl;

   // Fill in the call to the function that calculates highest grade
   highestGrade = findHighest(grades, numberOfGrades);
   cout << endl << "The highest grade is " << highestGrade << endl;
  
   // Fill in the call to the function that calculates lowest grade
   lowestGrade = findLowest(grades, numberOfGrades);
   cout << endl << "The lowest grade is " << lowestGrade << endl;
   // Fill in code to write the lowest to the screen
   return 0;
}

//********************************************************************************
// findAverage
//
// task: This function receives an array of integers and its size.
// It finds and returns the average of the numbers in the array
// precondition : array of floating point numbers
// postcondition : average of the numbers in the array
//
//********************************************************************************
float findAverage (const int grades[], int size)
{
   float sum = 0; // holds the sum of all the numbers
   for (int i = 0; i < size; i++)
   {
       sum = sum + grades[i];
   }
   return (sum / size); //returns the average
}

//****************************************************************************
// findHighest
//
// task: This function receives an array of integers and its size.
// It finds and returns the highest value of the numbers in the array
// precondition : array of floating point numbers
// postcondition : highest value of the numbers in the array
//
//****************************************************************************
int findHighest (const int grades[], int size)
{
   float highest = 0;
   for (int i = 0; i < size; i++)
   {
       if (grades[i] > highest)
       {
           highest = grades[i];
       }
   }
   return highest;
}

//****************************************************************************
// findLowest
//
// task: This function receives an array of integers and its size.
// It finds and returns the lowest value of the numbers in the array
// precondition : array of floating point numbers
// postcondition : lowest value of the numbers in the array
//
//****************************************************************************
int findLowest (const int grades[], int size)
{
   float lowest = 0;
   for (int i = 0; i < size; i++)
   {
       if (grades[i] < lowest)
       {
           lowest = grades[i];
       }
   }
   return lowest;
}

Having trouble to output the highest number, lowest number, and the average number. All I'm getting is 0 for all there. Also I using C++ as the programming language.

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

// This program will read in a group of test scores (positive integers from 1 to 100)
// from the keyboard and then calculate and output the average score
// as well as the highest and lowest score. There will be a maximum of 100 scores.

//

#include <iostream>
using namespace std;

float findAverage (const int[], int); // finds average of all grades
int findHighest (const int[], int); // finds highest of all grades
int findLowest (const int[], int); // finds lowest of all grades

int main()
{
int grades[100]; // the array holding the grades.
int numberOfGrades; // the number of grades read.
int pos = 0; // index to the array.
float avgOfGrades; // contains the average of the grades.
int highestGrade; // contains the highest grade.
int lowestGrade; // contains the lowest grade.

// Read in the values into the array pos = 0;
cout << "Please input a grade from 1 to 100, (or -99 to stop)" << endl;
    //modified
cin >> grades[pos++];//you are not incrementing index value
   //modified
while (grades[pos-1] != -99)
{   //modified
cin >> grades[pos++];
}
   //modified
numberOfGrades = pos-1; // Fill blank with appropriate identifier
// call to the function to find average

avgOfGrades = findAverage(grades, numberOfGrades);
cout << endl << "The average of all the grades is " << avgOfGrades << endl;

// Fill in the call to the function that calculates highest grade
highestGrade = findHighest(grades, numberOfGrades);
cout << endl << "The highest grade is " << highestGrade << endl;
  
// Fill in the call to the function that calculates lowest grade
lowestGrade = findLowest(grades, numberOfGrades);
cout << endl << "The lowest grade is " << lowestGrade << endl;
// Fill in code to write the lowest to the screen
return 0;
}

//********************************************************************************
// findAverage
//
// task: This function receives an array of integers and its size.
// It finds and returns the average of the numbers in the array
// precondition : array of floating point numbers
// postcondition : average of the numbers in the array
//
//********************************************************************************
float findAverage (const int grades[], int size)
{
float sum = 0; // holds the sum of all the numbers
for (int i = 0; i < size; i++)
{
sum = sum + grades[i];
}
return (sum / size); //returns the average
}

//****************************************************************************
// findHighest
//
// task: This function receives an array of integers and its size.
// It finds and returns the highest value of the numbers in the array
// precondition : array of floating point numbers
// postcondition : highest value of the numbers in the array
//
//****************************************************************************
int findHighest (const int grades[], int size)
{
float highest = 0;
for (int i = 0; i < size; i++)
{
if (grades[i] > highest)
{
highest = grades[i];
}
}
return highest;
}

//****************************************************************************
// findLowest
//
// task: This function receives an array of integers and its size.
// It finds and returns the lowest value of the numbers in the array
// precondition : array of floating point numbers
// postcondition : lowest value of the numbers in the array
//
//****************************************************************************
int findLowest (const int grades[], int size)
{
float lowest = grades[0];//   //modified
for (int i = 0; i < size; i++)
{
if (grades[i] < lowest)
{
lowest = grades[i];
}
}
return lowest;
}

output:

Please input a grade from 1 to 100, (or -99 to stop)
40
30
50
-99

The average of all the grades is 40

The highest grade is 50

The lowest grade is 30


Process exited normally.
Press any key to continue . . .


//PLS give a thumbs up if you find this helpful, it helps me alot, thanks.


//if you have any doubts, ask me in the comments

Add a comment
Know the answer?
Add Answer to:
// This program will read in a group of test scores (positive integers from 1 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
  • // PLACE YOUR NAME HERE #include <iostream> using namespace std; float findAverage (int [], int); //...

    // PLACE YOUR NAME HERE #include <iostream> using namespace std; float findAverage (int [], int); // finds average of all //grades int findHighest (int [], int); // finds highest of all //grades int findFirstFail( int[]); int main() { int grades[100]; // the array holding 100 grades. int numberOfGrades; // the number of grades read. int pos; // index to the array. float avgOfGrades; // contains the average of the grades. int highestGrade; // contains the highest grade. int inderOfFail; //...

  • Java Program 1. Write a class that reads in a group of test scores (positive integers...

    Java Program 1. Write a class that reads in a group of test scores (positive integers from 1 to 100) from the keyboard. The main method of the class calls a few other methods to calculate the average of all the scores as well as the highest and lowest score. The number of scores is undetermined but there will be no more than 50. A negative value is used to end the input loop. import java.util.Scanner; public class GradeStat {...

  • Implement and test a function that uses dynamic array to store students’ grades and calcuate the...

    Implement and test a function that uses dynamic array to store students’ grades and calcuate the average grade. // This program demonstrates the use of dynamic array // it #include <iostream> #include <iomanip> using namespace std; int main() { float *grades; // a pointer used to point to an array int size = 2; grades = new float[size];    int count = 0; // track the number of grade/student float grade; // the grade of a student float average, total;...

  • For this assignment, you are to write a program that does the following:  read temperatures...

    For this assignment, you are to write a program that does the following:  read temperatures from a file name data.txt into an array, and  after reading all the temperatures, output the following to the monitor: the average temperature, the minimum temperature, and the total number of temperatures read. In addition, the program must use the following functions: //precondition: fileName is name of the file to open, inFile is the input file //postcondition: inFile is opened. If inFile cannot...

  • What did I do wrong with this C++ code? Assume that we don't need to ask...

    What did I do wrong with this C++ code? Assume that we don't need to ask users for the number of students. #include <iostream> #include <iomanip> using namespace std; int main() { float *grades; // a pointer used to point to an array int size; int count = 0; // track the number of grade/student float grade; // the grade of a student float average, total; // average grade and total grades //**************start your code here************************ cout<<"How many student grades...

  • Fix this C++ code so that the function prototypes come before main. Main needs to be...

    Fix this C++ code so that the function prototypes come before main. Main needs to be declared first. Then call to the functions from inside of main. #include<cstdlib> using namespace std; //prompt user for input void getGrades(int gradeArray[],int size) { for(int i=0; i<size; i++) { cout<<"Enter the grade "<<i+1<<": "; cin>>gradeArray[i]; } } // finding average of all numbers in array float computeAverage(int numbers[],int size) { float sum=0; for(int i=0; i<size; i++) { sum = sum + numbers[i]; //compute sum...

  • Modify Assignment #18 so it drops each student’s lowest score when determining the students’ test score...

    Modify Assignment #18 so it drops each student’s lowest score when determining the students’ test score average and Letter grade. No scores less than 0 or greater than 100 should be accepted #include<iostream> #include<string> using namespace std; int main() { double average[5]; string name[5]; char grade[5]; for(int i=0; i<=5; i++) { cout<<"Enter student name: "; cin.ignore(); getline(cin,name[i]); int sum=0; for(int j=0; j<5; j++) { int grades; cout<<"Enter Grades:"<<j+1<<" : "; cin>>grades; sum+=grades; } average[i]=(float)sum/5; if(average[i]>=90 && average[i]<=100) grade[i]='A'; else if(average[i]>=80...

  • DO NOT use for loop and while loop Goal: Learn how to use recursive functions. General...

    DO NOT use for loop and while loop Goal: Learn how to use recursive functions. General requirement: Use cout to fully demonstrate your works for all tasks. The output must clearly show how each of these functions work. If no output is displayed for a task below, 0 point will be given to the task. If the output is not clear, some points may be deducted.    Task 1 – Reverse array (3 pts) Given an integer array like: const...

  • Use C++! This program uses the class myStack to determine the highest GPA from a list of students with their GPA.The program also outputs the names of the students who received the highest GPA. Redo t...

    Use C++! This program uses the class myStack to determine the highest GPA from a list of students with their GPA.The program also outputs the names of the students who received the highest GPA. Redo this program so that it uses the STL list and STL queue! Thank you! HighestGPAData.txt* 3.4 Randy 3.2 Kathy 2.5 Colt 3.4 Tom 3.8 Ron 3.8 Mickey 3.6 Peter 3.5 Donald 3.8 Cindy 3.7 Dome 3.9 Andy 3.8 Fox 3.9 Minnie 2.7 Gilda 3.9 Vinay...

  • howthe   output   of   the   following   4   program segments (a)    const int SIZE=8;    int values[SIZE]...

    howthe   output   of   the   following   4   program segments (a)    const int SIZE=8;    int values[SIZE] = {10, 10, 14, 16, 6, 25, 5, 8};    int index;    index=0;    res = values[index];    for (int j=1; j<SIZE; j++)    {        if (values[j] > res)        {            res = values[j];            index = j;        cout << index << res << endl;        }    }    cout <<...

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