I'm quite puzzled by why my variable NumberOfArrays changes the second time through the for loop in my code. Can anyone help me out?
#include <stdio.h>
#include <cs50.h>
int main(int argc, string argv[])
{
//variable declarations
int NumberOfArrays = 0;
int arrayRack[0];
//Get number of arrays
printf("Key in the number of arrays you'd like to have\n");
NumberOfArrays = GetInt();
//Get number for each element in arrayRack[]
for(int i = 0; i < NumberOfArrays; i++)
{
printf("give me an int for the %i th array\n", i + 1);
arrayRack[i] = GetInt();
// *** on the second pass, my "NumberOfArrays" gets adjusted to my GetInt number here. Why?
}
//print out numbers stored in respective arrays
for(int j = 0; j < NumberOfArrays; j++)
{
printf("{%i}<-- number in %ith array\n", arrayRack[j], j + 1);
}
return 0;
}
int main( void )for other functions, follow the function signature by a statement similar to:(void)parmName;int arrayRack[0];does not make any room for anything. The posted code does not get, from the user, the number of entries in each array. So getting that value needs to be added to the code. Then declare the arrays as:int arrayRack[ NumberOfArrays ][ NumberOfArrayEntries ];Then modify the rest of the code to actually input that number of entries for each array, Then modify the rest of the code to output all the entries in each array.