You declared maxLength, but
did not declare maxlength.
The C language is case sensitive -- those two are two different identifiers.
Taiwo A.
asked 04/27/22main21.cpp: In function ‘int main()’:
main21.cpp:49:26: error: ‘maxlength’ was not declared in this scope
if(qLength>maxLength) maxlength = qLength;
=================================
inline
float floatRand()
{
return ( ((float)rand()) / ((float)RAND_MAX) );
} // end floatRand
int main(void)
{
float item;
Queue q;
int qLength, maxLength; // added for exercise 7
int total; // added for exercise 8
// Initialize the random number generator.
srand((unsigned)time(NULL)); // srand(0) would make results easier to grade
// srand((int) getpid()); // *** replaced by above non-UNIX-specific line
// loop and total for exercise 8
total = 0;
for (int testRun = 0; testRun < 25; testRun++)
{
// Generate 100 random floats between 0 and 1. If the number
// is less than 0.5, it is put into the queue. If the number
// is 0.5 or greater, a number is removed from the queue.
qLength = 0;
maxLength = 0;
for (int i=0; i<100; ++i)
{
item = floatRand();
if (item < 0.5)
{
q.enqueue(item);
qLength++; // need to add two lines for exercise 7
if(qLength>maxLength) maxlength = qLength;
}
else
{
if (!q.qEmpty())
{
item = q.dequeue();
qLength--; // need to add one line for exercise 7
}
}
}
cout<<"Maximum Length of the queue is : "<<maxLength; // need to add one line for exercise 7 for printing
// need to add one line for exercise 8 for calculating total
while(!q.qEmpty())item = q.dequeue(); // clear out queue
}
// add one line for exercise 8 so as to print average maxiumum length
return 0;
} // end main
You declared maxLength, but
did not declare maxlength.
The C language is case sensitive -- those two are two different identifiers.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.