void GenerateClinic()
{
int NUM_DOCS = (rand() % 100) + 1; //cannot be used as a
constant
const int NUM_PATS = (rand() % 500) + 1; //cannot be used as a
constant
Doctor testDoc[NUM_DOCS]; //error is NUM_DOCS
Patient testPat[NUM_PATS]; //error is NUM_PATS
for (int i = 0; i < NUM_DOCS; i++)
{
int room = i;
int code = (rand() % 12) + 1; //random specialty code
//Doctor name becomes "doctor (index + 1)"
string number = to_string(i + 1);
string name = "doctor ";
name.append(number);
//sets doctor and assigns appropriately
testDoc[i].setName(name);
testDoc[i].setRoom(room);
testDoc[i].setCode(code);
assignGenerated(testDoc[i]);
}
Asked
Active
Viewed 109 times
0

NathanOliver
- 171,901
- 28
- 288
- 402
-
1error message is quite clear: for doing this "Doctor testDoc[NUM_DOCS]", NUM_DOCS must be constant / known at compilation time. Solution? Use std::vector or allocate the right amount of memory at runtime with the new keyword. Same for NUM_PATS – Mauro Dorni Apr 06 '21 at 15:40
-
`NUM_PATS` is `const`, but it it not a **compile-time constant**. `const int NUM_PATS = 3;` would be allowed, because its value is known when the code is being compiled. – Pete Becker Apr 06 '21 at 16:04