Should work and was working but now I get the Error C2143...
#include <stdio.h>
#include <stdlib.h>
int linear_search(int [][30], int, int, int);
float average(int [], int);
void table_size(void);
main()
{
int table[20][30];
int row, col, first, second, begin, end, temp, key, item, row_avg;
float avg;
table_size();
scanf("%d%d", &first, &second);
/*Takes care of data outside of range*/
while (((first < 1 || first > 20))||((second < 1 || second > 30))) {
printf("\nPlease follow the rules I have stated!\n\n");
table_size();
scanf("%d%d", &first, &second);
}
for (row = 0; row <= 19; row++) { /*Initializes the array to zero*/
/*Possibly take this out because of destructive read in of random numbers*/
for (col = 0; col <= 29; col++)
table[row][col] = 0;
}
/*Get range of number for random number generator*/
printf("Please enter two numbers for a range of random numbers:\n");
scanf("%d%d", &begin, &end);
if (begin > end) { /*Swap numbers if necessary*/
temp = begin;
begin = end;
end = temp;
}
else /*Else nothing is done*/
;
for (row = 0; row <= first - 1; row++) { /*Inputs random values into array*/
for (col = 0; col <= second - 1; col++)
table[row][col] = rand() % (end - begin + 1) + begin;
}
for (row = 0; row <= first - 1; row++) { /*Prints out the array for my checking*/
printf("\n"); /*will be the size they pick*/
for (col = 0; col <= second - 1; col++)
printf("%-5d", table[row][col]);
printf("\n");
}
/*Gets the number to search for, calls the function, and determines if it was found*/
printf("Please enter a value to search the table for: \n");
scanf("%d", &key);
item = linear_search(table, key, first, second);
for (row_avg = 0; row_avg <= second + 1; row_avg++) {
if (average(table[row_avg], second) == 0.0)
break;
else
printf("The average of row %d is %.2f\n", row_avg, average(table[row_avg], second));
return 0;
}
/Function-prompt for table size/
void table_size(void)
{
printf("\nPlease enter the dimensions of the array you would like\nto create"
", you cannot go larger than 20 rows by 30 columns:\n");
}
/Function-for checking for a value that the user picks/
int linear_search(int array[][30], int search_key, int x, int y)
{
int count, count2, found = 0;
for (count = 0; count <= x - 1; count++) {
for (count2 = 0;count2 <= y - 1; count2++) {
/*printf("%d & %d\n", count, count2);*/ /*Left in for debugging purposes*/
if (array[count][count2] == search_key) {
printf("\nFound value in row %d column %d\n", count + 1, count2 + 1);
found = 1;
break;
}
if (found == 1)
break;
}
if (found == 1)
break;
}
if (found == 0)
printf("\nValue not found at all buddy!\n");
return 0;
}
/Function-for calculating average/
float average(int array[], int y)
{
int count, total = 0;
for (count = 0; count <= y - 1; count++)
total += array[count];
/*printf("Total is %d\n", total);*/
return (float) total / y;
}