2

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;
    }

}
Jens Luedicke
  • 964
  • 2
  • 8
  • 20
Isaac Attuah
  • 119
  • 1
  • 11

1 Answers1

4

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

Tomasz Durda
  • 134
  • 1
  • 9
  • @IsaacAttuah ...because `Record` is not known at the point where the forward declarations are placed, move the declaration of `Record` before the forward declarations – 463035818_is_not_an_ai Apr 12 '18 at 10:29
  • @Thomas Thanks I fixed the problem.. I first repositioned and reworked the structure `struct Record { string fname[5], sname[5]; int marks[5], indexNum[5]; double average[5]; };` and did what you told me to do. Thanks again! – Isaac Attuah Apr 12 '18 at 10:58
  • Your edit to [my answer](https://stackoverflow.com/a/33856609/3597276) was rejected because it's not correct. `justify-items` and `justify-self` do not apply to flexbox. It's even in the [W3C link you provided](https://drafts.csswg.org/css-align-3/#propdef-justify-self): *"Applies to: block-level boxes, absolutely-positioned boxes, and grid items"*. No "flex items". – Michael Benjamin Apr 24 '18 at 17:40