Isaac Attuah
Isaac Attuah

Reputation: 119

How can I pass this structure into the available functions?

I need help passing a structure through a function to collect and print out its corresponding information. When I try and run the code below the compiler returns that I have too many arguments for the functions.

An image of my full code showing the corresponding errors

#include <iostream>
using namespace std;
int num;
void getInput();
void classBank();

struct Record
    {
        string fname, sname;
        int marks, indexNum;
        double average;
    };


int main()
{


    Record student;
    getInput();
    classBank(student);

}


void getInput()
{
    cout<<"How many people are you dealing with: ";
    cin >> num;
}

void classBank(struct student)
{

for(int i = 1; i < num; i++)
    {
       cin >> student[i].fname;
       cin >> student[i].sname;
       cin >> student[i].marks;
       cin >> student[i].indexNum;
       cin >> student[i].average;
    }

}

Upvotes: 2

Views: 90

Answers (1)

Tomasz Durda
Tomasz Durda

Reputation: 134

Replace

void getInput();
void classBank();

with

void getInput();
void classBank(Record student);

EDIT: That code won't work 'cause of several reasons:

  1. You declare functions that use struct Record, before declaration of Record
  2. You do not understand what keyword struct means
  3. You pass single element (without overloaded []), not an array to the classBank

EDIT2 Typo

Upvotes: 4

Related Questions