FlashpointPrdx
FlashpointPrdx

Reputation: 11

What could be the issue with my main function calls?

This program is meant to call to read_in, sum_row, and print. However, I am getting error messages saying that these functions are not declared in this scope. How can I fix this? I'm sure its somewhat of an easy fix but I am just starting to learn function calls and I can't for the life of me figure this out. Any help is very much appreciated, thank you!

#include <iostream>
#include <iomanip>

using namespace std;

int sum = 0;
int row = 0;
int col = 0;

const int stud_num_rows = 28;
const int stud_num_cols = 10;

const int fac_num_rows = 15;
const int fac_num_cols = 10;

const int staff_num_rows = 100;
const int staff_num_cols = 10;

const int adm_num_rows = 30;
const int adm_num_cols = 10;

int main()
{
    
    int students[28][10];
    int faculty[15][10];
    int staff[100][10];
    int admin[30][10];
    
    read_in(students, faculty, staff, admin);
    
    sum_row(students, faculty, staff, admin);
    
    print(students, faculty, staff, admin);
    
    return 0;
}

void read_in(int students[][stud_num_cols],
             int faculty[][fac_num_cols],
             int staff[][staff_num_cols],
             int admin[][adm_num_cols])
{
    for (row = 0; row < stud_num_rows; row++)
        for (col = 0; col < stud_num_cols; col++)
            cin >> students[row][col];
    
    for (row = 0; row < fac_num_rows; row++)
        for (col = 0; col < fac_num_cols; col++)
            cin >> faculty[row][col];
    
    for (row = 0; row < staff_num_rows; row++)
        for (col = 0; col < staff_num_cols; col++)
            cin >> staff[row][col];
    
    for (row = 0; row < adm_num_rows; row++)
        for (col = 0; col < adm_num_cols; col++)
            cin >> admin[row][col];
}

void sum_row(int students[][stud_num_cols],
             int faculty[][fac_num_cols],
             int staff[][staff_num_cols],
             int admin[][adm_num_cols])
{
    row = 1;
    
    cout << "The sum of the first row of each array is:" << endl;
    
    for (col = 0; col < stud_num_cols; col++)
    {
        sum = sum + students[row][col];
    }
    cout << left << setw(5) << "Students:" << sum << endl;
    
    for (col = 0; col < fac_num_cols; col++)
    {
        sum = sum + faculty[row][col];
    }
    cout << left << setw(5) << "Students:" << sum << endl;
    
    for (col = 0; col < staff_num_cols; col++)
    {
        sum = sum + staff[row][col];
    }
    cout << left << setw(5) << "Students:" << sum << endl;
    
    for (col = 0; col < adm_num_cols; col++)
    {
        sum = sum + admin[row][col];
    }
    cout << left << setw(5) << "Admin:" << sum << endl;
}

void print(int students[][stud_num_cols],
           int faculty[][fac_num_cols],
           int staff[][staff_num_cols],
           int admin[][adm_num_cols])
{
    for (row = 0; row < stud_num_rows; row++)
        for (col = 0; col < stud_num_cols; col++)
            cout << setw(5) << students[row][col] << " ";
    cout << endl;
    
    for (row = 0; row < fac_num_rows; row++)
        for (col = 0; col < fac_num_cols; col++)
            cout << setw(5) << faculty[row][col] << " ";
    cout << endl;
    
    for (row = 0; row < staff_num_rows; row++)
        for (col = 0; col < staff_num_cols; col++)
            cout << setw(5) << staff[row][col] << " ";
    cout << endl;
    
    for (row = 0; row < adm_num_rows; row++)
        for (col = 0; col < adm_num_cols; col++)
            cout << setw(5) << admin[row][col] << " ";
    cout << endl;
}

Upvotes: 0

Views: 43

Answers (1)

Eugene
Eugene

Reputation: 7688

You have to either move other functions above main(), or put function prototypes above main().

Upvotes: 1

Related Questions