alright, so I got the loop figured out, but when i call the function in main, it says my arraySize counter is uninitialized. I'm pretty sure it has to do with the * and & ordeal. This is the error I receive: In function 'main', 'arraySize' is used uninitialized in this function. Any help would be great.
Code:
#include <stdio.h>
int getBoard ();
void triangleTests (int length[] , int arraySize);
int main (void)
{
int arraySize;
int length[10];
getBoard ();
triangleTests (length, arraySize);
return 0;
}
int getBoard ()
{
int length[10]; //ARRAY FOR ALL THE TRIANGLES SIDE LENGTHS
int arraySize = 0; //COUNTER FOR THE ARRAY
int temp;
while (arraySize < 10 && temp != -1)
{
printf("Enter the length of board #%d: ", (arraySize + 1));
scanf("%d", &temp);
if (temp > 0)
{
arraySize++;
temp = length[arraySize];
}
else if (temp < -1)
{
printf("\n\nInvalid negative input! Please try again!\n");
}
}
return arraySize;
}
void triangleTests(int length[], int arraySize)
{
int counterA;
int counterB;
int counterC;
int perimLongest; //KEEPS TRACK OF LARGEST PERIMETER COUNTER
int triCount; //COUNTS NUMBER OF TRIANGLES THAT CAN BE MADE
perimLongest = 0;
triCount = 0;
counterA = 1;
counterB = 2;
counterC = 3;
while(counterA <= arraySize)
{
while(counterB <= arraySize)
{
while(counterC <= arraySize)
{
if((length[counterA] + length[counterB]) > length[counterC])
{
if((length[counterA] + length[counterC]) > length[counterB])
{
if((length[counterB] + length[counterC]) > length[counterA])
{
triCount = triCount + 1;
if(perimLongest < (length[counterA] + length[counterB] + length[counterC]))
{
perimLongest = length[counterA] + length[counterB] + length[counterC];
}
}
}
}
counterC = counterC + 1;
}
counterB = counterB + 1;
}
counterA = counterA + 1;
counterB = counterA + 1;
counterC = counterB + 1;
}
printf("The maximum perimeter is %d",perimLongest);
printf("The total number of triangles possible is: %d",triCount);
return;
}