#include <iostream>
usingnamespace std;
// FUNCTION
int nextVisitor( int x, bool stalls[])
{
int i;
int count = 0;
int finalcount = 0;
int place = 0;
for ( i = 0; i <=(x-1); i++)
stalls[i] = false;
i = 0;
while (i <= (x-1))
{
if (stalls[i] == false)
{
count++;
i++;
}
else
{
if (count > finalcount)
{
place = i;
}
}
}
count = count /2;
place = place + count;
stalls[place] = true; // visitor goes here
// print array
for (i =0; i <= 9; i++)
cout << stalls[i];
//print array
return 0;
}
//FUNCTION END
int main()
{
int length;
cout << "How many stalls are there?" << endl;
cin >> length;
bool *stArray;
*stArray = newbool[length];
nextVisitor(length, *stArray);
delete[] stArray;
return 0;
}
here are the errors I get, around line 60
1>------ Build started: Project: project3, Configuration: Debug Win32 ------
1> project3.cpp
1>c:\users\jam\documents\visual studio 2010\projects\project3\project3\project3.cpp(58): warning C4800: 'bool *' : forcing value to bool 'true' or 'false' (performance warning)
1>c:\users\jam\documents\visual studio 2010\projects\project3\project3\project3.cpp(60): error C2664: 'nextVisitor' : cannot convert parameter 2 from 'bool' to 'bool []'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I can now run the program but I get a runtime error after the amount of stalls is input saying stArray isn't initialized. What would I add to initialize it? Thsi is my first program pulling from the heap so I'm struggling with some of the details.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int length;
int j;
cout << "How many stalls are there?" << endl;
cin >> length;
bool *stArray;
*stArray = newbool[length];
for ( j = 0; j <=(length-1); j++)
stArray[j] = false;
nextVisitor(length, stArray);
delete[] stArray;
return 0;