Hi, I'm a computer science student in college right now and I'm having trouble with a program I'm writing. The goal of the program is to:
"Write a menu-driven program that allows the user to fill an array of 50 integers with random numbers in the range 1...999, sort it, and then search it to determine if a given random number was generated. The menu is shown below
MENU
Select one of the following options:
F. Fill array with a random number series
P. Print the array
S. Sort the array
Q. Query the array
Z. Terminate the program
-Each time the fill option is executed, it will fill the array with a new random number series.
-You may use any of the sorts discussed int he text.
-If the query locates the number, it will print a message that the number was located and the index location where it was found.
-If the query does not locate the number, it will print a message that the number was not in the list and then print the value and index location of the largest number less than the target and the smallest value greater than the requested number. Note that the first and last elements will not have both a smaller and larger value.
-If the array has been sorted, the query will use a binary search. If it is not sorted, it will use the sequential search.
To test the program:
a. Fill (F) the array.
b. Print (P) the unsorted array.
c. Search (Q) the first, last, and a middle element.
d. Refill (F) the array.
e. Sort (S) the array.
f. Print (P) the sorted array.
g. Search (Q) the first, last, and a middle element.
h. Search (Q) for a number less than the first, greater than the last, and not found in the middle of the list."
So yeah, it took forever to type that, anyway heres what I've done so far.
Code:
//Exercise 56 p. 555
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void fillArray(int i, double *x[]);
void printArray(int i, double x[]);
main()
{
char choice[1];
double myArray[50];
int exit = 0;
myArray[1] = 9999999;
while(exit == 0)
{
system("cls");
printf("Here are your options: \n");
printf("F. Fill an array with a random number series\n");
printf("P. Print the array\n");
printf("S. Sort the array\n");
printf("Q. Query the array\n");
printf("Z. Terminate the program\n");
printf("Selection: ");
scanf("%c", &choice[0]);
switch(choice[0])
{
case 'f': case 'F': fillArray(50, &myArray);
printf("\n");
system("pause");
break;
case 'p': case 'P': if(myArray[1] != 9999999)
{
printArray(50, myArray);
printf("\n");
system("pause");
break;
}
else
{
printf("You must first fill the array!\n");
system("pause");
break;
}
case 'z': case 'Z': exit = 1;
}
}
system("pause");
}
void fillArray(int i, double *x[])
{
int b = 0;
srand(time(NULL));
while(b < i)
{
*x[b] = rand()%999+1;
b++;
}
}
void printArray(int i, double x[])
{
int b = 0;
while(b<i);
{
printf("Array %d: %.0lf\n", b+1, x[]);
b++;
}
}
The error I'm getting is coming up here:
Code:
case 'f': case 'F': fillArray(50, &myArray);
This is the first case in my switch. And heres the error that I'm getting:
"[Warning] passing arg 2 of `fillArray' from incompatible pointer type"
I've checked the code and have no idea why it's saying that. Anyone have an idea?