struct

I have a lot of errors and unable to solve these due to lack of knowledge. Pls help me what do I make mistake!

Thanks

#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <iomanip>
//10
#include <cstring>
using namespace std;

const int nsize = 24;

// STRUCT
struct srecord {
string sname[nsize];
int score;
};
//21

Last edited on
dimension of an array shall be a constant expression. So this statement

srecord highscore [size] ;


is invalid because size is not a constant expression.
Can I define dynamic struct upon variable size?
If I fixed size to 3, my program will run only 3 students records.
If I do dynamic size, I could run different number of student records.

Pls amend if I am wrong.
Thks
Last edited on
I change my code to srecord *highscore = new highscore[size]; then I got lesser errors. But dont not how to clear error,
Pls help . Thks



#include <string>

using namespace std;

const int nsize = 24;

// STRUCT
struct srecord {
string sname[nsize];
int score;
};
//21


// Declare function prototype
//---------------------------

void initializeData(srecord highscore[], int);
void sortarray(srecord highscore[], int);
void display(srecord highscore[], int);
//31


int main()
//-------
{
string tname;
int size;
//41
cout << "How many score will you enter? ";
cin >> size;

// declaration of size with dynamic memory allocation
srecord *dynhs

dynhs = new srecord[size];


initializeData(dynhs, size);
sortarray(dynhs, size);
display(dynhs,size);

delete[] dynhs;
// delete[] score;

return 0;
}
Last edited on
Topic archived. No new replies allowed.