I need help creating a nested for
loop. This is for "Jump Game" and basically there is an array with some numbers in it. The number at each array[position]
has a certain number of times it can jump to reach the end. Ex: [2 3 1 1 4 0]
so array[0] = 2
and it can jump 2 or 1 places, array[1] = 3
and can jump 3,2, or 1 places. Ex: [3 2 1 0 4 0]
so you basically can never reach the position in the array.
I've been going at it for a while and can't come up with the loop. The readFromFile
just basically creates the array size. Now that I have the size I need to check each number which I am stuck on.
void readFromFile(int list[], int& size, ifstream& infile)
{
infile >> list[size];
while (!infile.eof()) // Loops until end of file is reached
{
size++;
infile >> list[size];
}
infile.close();
return;
}
bool getToLastIndex(int list[], int size)
{
for(i=0; i< size;i++)
{
if(list[i] == 0)
break;
j=i+list[i]; //Resetting it for a new jump or section on array?
i=j;
for(int j=0; j <= list[i]; j++)
{
list[j] == return true;
}
}
}
I want to be able to use
getToLastIndex(list,size);
if(getToLastIndex() == true)
{
cout << "Mario FTW" << endl; // Got to the end
}
else
cout << "This bridge has the workings of bowser all over it >:( " << endl; //Couldnt make it to the end
The homework is Mario themed... I didn't choose the outputs