0

`

#include <iostream>
#include <iomanip>
using namespace std;

void getGrades(double g[], const int SIZE)
{
    cout << "Please enter " << SIZE << " grades:" << endl;
    for(int i = 0; i < SIZE; i++)
    {
        cin >> g[i];
    }
}

double getAverage(double g[], const int SIZE)
{
    int total = 0;
    for(int i = 0; i < SIZE; i++)
    {
        total += g[i];
    }
    return total/SIZE;
}

void findDropInfo(double g[], const int SIZE, int &lowest, double average)
{
  int total = 0;
  lowest = g[0];
    for(int i = 1; i < SIZE; i++)
    {
      if (lowest > g[i]) {
      lowest = g[i];
        }
    }
  average = (total - lowest)/SIZE;
  return average;
}

void printData(double g[], int lowest, double average, double avg_before)
{
  cout << "The 5 grades entered by the user are:" << endl;
  cout << g[];
  cout << "Grade dropped: " << lowest << endl;
  cout << "Final Average: " << average << endl;
  cout << "Average before drop: " << avg_before << endl;
}
// TODO: Complete the function definitions

int main()
{
    const int SIZE = 5;
    double grades[SIZE];
    int lowest;
    double avg,
           avgBeforeDrop;

    // TODO: Add function calls

  getGrades(grades[SIZE], SIZE);

  getAverage(grades[SIZE], SIZE);

  findDropInfo(grades[SIZE], SIZE, lowest, avg);

  printData(grades[SIZE], lowest, avg, avgBeforeDrop);
  

    return 0;
}


`

Whenever I run the program, I get multiple errors saying there's no matching candidate function. I'm not sure if the problems are in the functions themselves or in the function calls, but from what I know the functions themselves should be fine. I'm also told there's an expected expression in g[] but I' not sure what's wrong there either, as it's meant to be empty.

  • `getGrades(grades[SIZE], SIZE);` -> `getGrades(grades, SIZE);` and similarly for other calls. – Igor Tandetnik Nov 09 '22 at 02:43
  • Forget that C-style arrays exist in the language. Switch to `std::array` or `std::vector` instead. That would be a good first step. – Jesper Juhl Nov 09 '22 at 02:43
  • 1
    It is preferred that you cut and paste the exact text of any errors you got, especially compiler errors. You may redact paths and personal info if necessary. – Wyck Nov 09 '22 at 02:43
  • [Why is "using namespace std;" considered bad practice?](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) – Jesper Juhl Nov 09 '22 at 02:46
  • I changed the calls to remove the [SIZE] from grades, all that's left is the "error: expected expression cout << g[];", but thank you so much for the help so far! – Magolor Nov 09 '22 at 02:47
  • What do you expect `cout << g[];` to do? Whatever you expect I can guarantee that it doesn't do that. – Jesper Juhl Nov 09 '22 at 02:47
  • I need cout << g[]; to display the array of grades, and this was how I was told to do it by my professor. – Magolor Nov 09 '22 at 02:48
  • @Magolor "I need cout << g[]; to display the array of grades, and this was how I was told to do it by my professor." - Then either you misunderstood your professor or he/she is simply wrong, because that's *not* what that code does. – Jesper Juhl Nov 09 '22 at 02:51
  • What's the correct way to output the array to the screen if I may ask? I tried just cout << g; but it gave me a mess of numbers and a few letters. – Magolor Nov 09 '22 at 02:56
  • If you don't know how to do something in C++, making random guesses at to what the syntax is is unlikely to succeed, you have to look it up in your C++ textbook. There's nothing in C++ to do this, you have to write the code to do it yourself. If your professor told you to do `cout << g[]` then what you should need to do is find a different professor who actually knows C++. – Sam Varshavchik Nov 09 '22 at 03:05

1 Answers1

0

Most issues have already been resolved in the comments, but note: cout << g[] does not print the elements of g. The way to do this is

char separator = /* the character you want to use to separate the printed elements of g */
for (int i = 0; i < SIZE; i++)
{
   cout << g[i] << separator;
}
if (separator != '\n') cout << '\n'; //this is to put the next print on the next line

I would put this as a comment but I don't have enough reputation :|