Mar 31, 2013 at 9:17pm UTC
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 Apr 2, 2013 at 5:45am UTC
Mar 31, 2013 at 9:23pm UTC
dimension of an array shall be a constant expression. So this statement
srecord highscore [size] ;
is invalid because size is not a constant expression.
Mar 31, 2013 at 9:30pm UTC
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 Mar 31, 2013 at 9:32pm UTC
Mar 31, 2013 at 9:39pm UTC
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 Mar 31, 2013 at 10:46pm UTC