M
MathewLovesC
Can someone help me out here? I have a bunch of test statements in the
program and my test printf("Do I have trouble here after
GetNumbers()?\n"); does not display rather I get garbage. Please help.
#include <stdio.h>
#include <system.h>
//prototypes
char DisplayTitle(void);
void GetNumbers(int *parrNumb);
int FindMax(int *parrNumb);
int FindMin(int *parrNumb);
void DisplayNumbers(int min, int max);
int main(void)
{
char quitNow='a'; /* to determine if uer wants to quit */
int min=0; /* minimum number in array */
int max=0; /* maximum number in array */
int arrNumb[10]; /* user input into array */
int *parrNumb; /* pointer to array */
int i=0; /* used as a counter in array */
for (i=0; i<10; i++) /* initialize array to 0's */
arrNumb = 0;
//display the title of the program
quitNow = DisplayTitle();
if (quitNow=='Q' || quitNow=='q')
{
return 0;
}
//printf("Do I have trouble here before GetNumbers()?\n");
//Get all 10 numbers from user
GetNumbers(arrNumb[10]);
printf("Do I have trouble here after GetNumbers()?\n");
//Find minimum number in array
min = FindMin(arrNumb[10]);
printf("\nmin is: %i",min);
//Find maximum number in array
max = FindMax(arrNumb[10]);
printf("\nmin is: %i",min);
printf("\nmax is: %i",max);
printf("Do I have trouble here before DisplayNumbers()?\n");
//display the output
DisplayNumbers(min, max);
printf("Do I have trouble here after DisplayNumbers()?\n");
fflush(stdin);
printf("\nPress any key to end.");
getche();
return 0;
}
/* DisplayTitle Function
Input : Non
Process: Displays Title and Instructions
Output : None
*/
char DisplayTitle(void)
{
char quitNow; /* does user want to exit program */
clrscr();
printf("Array Program\n");
printf("-----------------------------------------------------------------\n");
printf("Application will ask for 10 numbers and then return the
largest\nand smallest numbers.\n");
printf("Enter (Q) to Quit Application or press any other key to
continue.\n");
printf("-----------------------------------------------------------------\n");
scanf("%c",&quitNow);
fflush(stdin);
return quitNow;
}
/* GetNumbers Function
Input : Array of integers
Process: Get user's input (up to 10 times)
Output : None. Values returned through pointer
*/
void GetNumbers(int *parrNumb)
{
int getnumb=0; /* user choice from menu passed to main */
int count; /* used to determine when 10 numbers added */
for(count=0;count<10;count++)
{
printf("Please enter a number.\n");
scanf("%d",parrNumb);
fflush(stdin);
printf("GetNumber is : %d\n",*parrNumb);
printf("INDEX IS %i\n",count);
*parrNumb++;
getnumb=0; /*reinitialize*/
}
}
/* FindMax Function
Input : Pointer to array
Process: Finds maximum number in array
Output : Returns maximum number
*/
int FindMax(int *parrNumb)
{
int maxNumb=0; /* used to store maximum number of array */
int i=0; /* used as a counter for the array */
maxNumb = *parrNumb;
for (i=1; i<10; i++) /* initialize array to 0's */
{
*parrNumb++; /* go to next index */
if (*parrNumb>maxNumb)
{
maxNumb = *parrNumb;
}
}
return maxNumb;
}
/* FindMin Function
Input : Pointer to array
Process: Finds minimum number in array
Output : Returns minimum number
*/
int FindMin(int *parrNumb)
{
int minNumb=0; /* used to store minimum number of array */
int i=0; /* used as a counter for the array */
minNumb = *parrNumb; /* assign first index to minNumb */
for (i=1; i<10; i++) /* initialize array to 0's */
{
*parrNumb++; /* go to next index */
if (*parrNumb<minNumb)
{
minNumb = *parrNumb;
}
}
return minNumb;
}
/* DisplayNumbers Function
Input : Minimum number in array and maximum number in array
Process: Displays minimum and maximum numbers
Output : None
*/
void DisplayNumbers(int min, int max)
{
//clrscr();
printf("\nThe minimum number in the array is %i.",min);
printf("\nThe maximum number in the array is %i.",max);
}
program and my test printf("Do I have trouble here after
GetNumbers()?\n"); does not display rather I get garbage. Please help.
#include <stdio.h>
#include <system.h>
//prototypes
char DisplayTitle(void);
void GetNumbers(int *parrNumb);
int FindMax(int *parrNumb);
int FindMin(int *parrNumb);
void DisplayNumbers(int min, int max);
int main(void)
{
char quitNow='a'; /* to determine if uer wants to quit */
int min=0; /* minimum number in array */
int max=0; /* maximum number in array */
int arrNumb[10]; /* user input into array */
int *parrNumb; /* pointer to array */
int i=0; /* used as a counter in array */
for (i=0; i<10; i++) /* initialize array to 0's */
arrNumb = 0;
//display the title of the program
quitNow = DisplayTitle();
if (quitNow=='Q' || quitNow=='q')
{
return 0;
}
//printf("Do I have trouble here before GetNumbers()?\n");
//Get all 10 numbers from user
GetNumbers(arrNumb[10]);
printf("Do I have trouble here after GetNumbers()?\n");
//Find minimum number in array
min = FindMin(arrNumb[10]);
printf("\nmin is: %i",min);
//Find maximum number in array
max = FindMax(arrNumb[10]);
printf("\nmin is: %i",min);
printf("\nmax is: %i",max);
printf("Do I have trouble here before DisplayNumbers()?\n");
//display the output
DisplayNumbers(min, max);
printf("Do I have trouble here after DisplayNumbers()?\n");
fflush(stdin);
printf("\nPress any key to end.");
getche();
return 0;
}
/* DisplayTitle Function
Input : Non
Process: Displays Title and Instructions
Output : None
*/
char DisplayTitle(void)
{
char quitNow; /* does user want to exit program */
clrscr();
printf("Array Program\n");
printf("-----------------------------------------------------------------\n");
printf("Application will ask for 10 numbers and then return the
largest\nand smallest numbers.\n");
printf("Enter (Q) to Quit Application or press any other key to
continue.\n");
printf("-----------------------------------------------------------------\n");
scanf("%c",&quitNow);
fflush(stdin);
return quitNow;
}
/* GetNumbers Function
Input : Array of integers
Process: Get user's input (up to 10 times)
Output : None. Values returned through pointer
*/
void GetNumbers(int *parrNumb)
{
int getnumb=0; /* user choice from menu passed to main */
int count; /* used to determine when 10 numbers added */
for(count=0;count<10;count++)
{
printf("Please enter a number.\n");
scanf("%d",parrNumb);
fflush(stdin);
printf("GetNumber is : %d\n",*parrNumb);
printf("INDEX IS %i\n",count);
*parrNumb++;
getnumb=0; /*reinitialize*/
}
}
/* FindMax Function
Input : Pointer to array
Process: Finds maximum number in array
Output : Returns maximum number
*/
int FindMax(int *parrNumb)
{
int maxNumb=0; /* used to store maximum number of array */
int i=0; /* used as a counter for the array */
maxNumb = *parrNumb;
for (i=1; i<10; i++) /* initialize array to 0's */
{
*parrNumb++; /* go to next index */
if (*parrNumb>maxNumb)
{
maxNumb = *parrNumb;
}
}
return maxNumb;
}
/* FindMin Function
Input : Pointer to array
Process: Finds minimum number in array
Output : Returns minimum number
*/
int FindMin(int *parrNumb)
{
int minNumb=0; /* used to store minimum number of array */
int i=0; /* used as a counter for the array */
minNumb = *parrNumb; /* assign first index to minNumb */
for (i=1; i<10; i++) /* initialize array to 0's */
{
*parrNumb++; /* go to next index */
if (*parrNumb<minNumb)
{
minNumb = *parrNumb;
}
}
return minNumb;
}
/* DisplayNumbers Function
Input : Minimum number in array and maximum number in array
Process: Displays minimum and maximum numbers
Output : None
*/
void DisplayNumbers(int min, int max)
{
//clrscr();
printf("\nThe minimum number in the array is %i.",min);
printf("\nThe maximum number in the array is %i.",max);
}