-4

for starters I'm new to coding so I am sure some of this code will look nasty and probably hard to understand. The program is supposed to have the user enter 5 classes, and 5 test scores for each class, then using functions, I need to find the lowest test score, highest test score, and the average of the scores for each class, all of which I have done in there respective functions. Then display it all using another function, there is my problem. I think it is a simple fix, but I am not sure, all I need to do is call the display function from main, and then have it display, but it just gives me syntax errors every time. Like I said, I think it will be an easy fix, but I am not sure. Any help would be appreciated!

#include "stdafx.h"
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int minfun(int lowest, int test[5][5])
{
    for (int a = 0; a < 5; a++)
    {
        for (int i = 0; i < 5; i++)
        {
            if (test[a][i] < lowest)
            {
                lowest = test[a][i];
            }
        }
    }
    return lowest;
}

int maxfun(int highest, int test[5][5])
{
    for (int a = 0; a < 5; a++)
    {
        for (int i = 0; i < 5; i++)
        {
            if (test[a][i] > highest)
            {
                highest = test[a][i];
            }
        }
    }
    return highest;
}

double classavg(double avg, int sum, int test[])
{
    for (int a = 0; a < 5; a++)
    {
        for (int i = 0; i < 5; i++)
        {
            sum = sum + test[a];
        }
    }
    avg = sum / 5;
    return avg;
}

void display(string classes[], int test[], int lowest, int highest, double avg)
{
    minfun(lowest, test[5]);
    maxfun(highest, test[5]);
    classavg(avg, sum, test[5]);
    for (int a = 0; a < 5; a++)
        {
        for (int i = 0; i < 5; i++)
            {
                cout << "=============================================================" << endl;
                cout << "Displaying stats for " << classes[a] << endl;
                cout << "Lowest test score for " << classes[a] << " is: " << lowest << endl;
                cout << "Highest test score for " << classes[a] << " is: " << highest << endl;
                cout << "The average for " << classes[a] << "is: " << avg << endl;
                cout << "=============================================================" << endl;
            }
        }
    //needs for loop to display stats for each class
}

int main()
{
    const int max_test = 5;
    int lowest = 100;
    int highest = 0;
    int sum = 0;
    double avg = 0;
    string classes[5];
    int test[5][5];

    cout << "Enter the name of your first class: ";
    getline (cin,classes[0]);
    cout << "Enter the name of your second class: ";
    getline (cin, classes[1]);
    cout << "Enter the name of your third class: ";
    getline(cin, classes[2]);
    cout << "Enter the name of your fourth class: ";
    getline(cin, classes[3]);
    cout << "Enter the name of your fifth class: ";
    getline(cin, classes[4]);
    cout << "=============================================================" << endl;
    for (int a = 0; a <= max_test; a++)
    {
        for (int i = 1; i <= max_test; i++)
        {
            cout << "Enter score for test " << i << " in " << classes[a] << " : ";
            cin >> test[a][i];
        }
        cout << "=============================================================" << endl;
    }
    cout << "=============================================================" << endl;
    display(lowest, highest, avg);
    system("pause");
    return 0;
}
zhodges10
  • 5
  • 3
  • do you mean this error? `error: invalid conversion from ‘int’ to ‘int (*)[5]’ [-fpermissive] minfun(lowest, test[5]);` – Arash Nov 13 '17 at 02:42
  • 1
    "there is my problem", well where is it? If you point to the problem, on your screen, that doesn't really help anyone else who might want to read this large chunk of code. – Sam Varshavchik Nov 13 '17 at 02:44
  • 1
    *this is my problem* is only useful if you've actually explained a problem, which you have not, and *it just gives me syntax errors every time* is absolutely useless unless you tell us what that syntax error is - it's **right on the screen in front of you**, so there is absolutely no reason you can't provide it to us in your post as well. Clearly you've seen it, because you knew it was a syntax error. It's text, on your screen, just like your code. – Ken White Nov 13 '17 at 02:44
  • A problem with calling the `display` function is that the function expects 5 parameters and you just give it 3. – Bo Persson Nov 13 '17 at 02:47
  • The problems I have are derived from the display function, and from the display(lowest, highest, avg); line I have at the bottom of main. Arash was correct, I get that error for these two lines in the display function: minfun(lowest, test[5]);maxfun(highest, test[5]); – zhodges10 Nov 13 '17 at 02:56
  • You provide `test[5]` and the function expects `int test[5][5]`. Obviously the number of dimensions is't right, but it's a bit worse than that. `int test[5][5]` means the function expects a 2 dimensional array that is a 5x5 grid. `test[5]` provides the 6th element (arrays are origin 0) of test, which in this case is a single element in a 1 dimensional array. So, one is asking for 5x5 (25) `int`s and you gave it 1 `int`. This problem is better resolved by [reading a good book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) than with Stack Overflow. – user4581301 Nov 13 '17 at 04:15

1 Answers1

0

you have problem passing parameters to a function , i suggest you look that up.. BTW I've made your variables static and fixed up some errors .. and it seems to work Kudos..

#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
static string classes[5];
static int test[5][5];
static const int max_test = 5;
static int lowest = 100;
static int highest = 0;
static int sum = 0;
static double avg = 0;

int minfun(int lowest)
{
    for (int a = 0; a < 5; a++)
    {
        for (int i = 0; i < 5; i++)
        {
            if (test[a][i] < lowest)
            {
                lowest = test[a][i];
            }
        }
    }
    return lowest;
}

int maxfun(int highest)
{
    for (int a = 0; a < 5; a++)
    {
        for (int i = 0; i < 5; i++)
        {
            if (test[a][i] > highest)
            {
                highest = test[a][i];
            }
        }
    }
    return highest;
}

double classavg(double avg)
{
    for (int a = 0; a < 5; a++)
    {
        for (int i = 0; i < 5; i++)
        {
            sum = sum + test[a][i];
        }
    }
    avg = sum / 5;
    return avg;
}

void display(int lowest, int highest, double avg)
{
    minfun(lowest);
    maxfun(highest);
    classavg(avg);
    for (int a = 0; a < 5; a++)
        {
        for (int i = 0; i < 5; i++)
            {
                cout << "=============================================================" << endl;
                cout << "Displaying stats for " << classes[a] << endl;
                cout << "Lowest test score for " << classes[a] << " is: " << lowest << endl;
                cout << "Highest test score for " << classes[a] << " is: " << highest << endl;
                cout << "The average for " << classes[a] << "is: " << avg << endl;
                cout << "=============================================================" << endl;
            }
        }
    //needs for loop to display stats for each class
}

int main()
{


    cout << "Enter the name of your first class: ";
    getline (cin,classes[0]);
    cout << "Enter the name of your second class: ";
    getline (cin, classes[1]);
    cout << "Enter the name of your third class: ";
    getline(cin, classes[2]);
    cout << "Enter the name of your fourth class: ";
    getline(cin, classes[3]);
    cout << "Enter the name of your fifth class: ";
    getline(cin, classes[4]);
    cout << "=============================================================" << endl;
    for (int a = 0; a <= max_test; a++)
    {
        for (int i = 1; i <= max_test; i++)
        {
            cout << "Enter score for test " << i << " in " << classes[a] << " : ";
            cin >> test[a][i];
        }
        cout << "=============================================================" << endl;
    }
    cout << "=============================================================" << endl;
    display(lowest, highest, avg);
    system("pause");
    return 0;
}