Sunday, June 26, 2022

[FIXED] Why does my code say that it has an incomplete type even after I tried declaring it?

Issue

I am writing a program that displays a number of students test scores in the form of a table and then calculates and displays the average. Upon running the code, I get the following errors(also pictured below): variable has incomplete type 'struct students' struct students st[50]; ^ note: forward declaration of 'students' struct students st[50];

I have declared students and have tried declaring st and I am just not sure what the problem is. Below is a typed version and a screenshot of my code:

#include <iostream>
using namespace std;
int Main()
{
  int students;

   struct students st[50]; 
   return 0;
}

Code errors Picture of typed code


Solution

You have to define it first. You can also use this style.

struct student{
    ...
};

int main{
    student* st[50];
    for(int i=0; i<50;i++)
        st[i]=new student;
    return 0;
}


Answered By - emtsdmr
Answer Checked By - Clifford M. (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.