# Thread: Array and other problems

1. ## Array and other problems

im making a highest number program with counter and a multiplication program with array and im not sure where im going wrong, the highest number always comes out at 0, and in the multiplication the number always gets * by 12 (the ending number), thanks for any help on this problem! and sorry its a bit of a mess lol

Code:
```#include "stdafx.h"
#include <stdlib.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

int main ()
{
int choice = 0;
int multi = 0;
int x = 0;
int x1 = 0;
int x2 = 0;
int highest = 0;
int num1 = 0;
int num2 = 0;
int total = -1;

printf("\n1:Highest Number\n");
printf("2:Muliplication Table\n");
scanf("%c",&choice);
system ("cls");

switch (choice)
{
case '1':
printf("Highest Number Calc\n\n");

do{
printf("\nPlease Input a number or input -999 to finish\n");
int highest(int, int);
scanf("%d", &num1);

total = total + 1;

}while (num1 != -999);

printf("%d, is the highest number and there where %d, numbers inputed", highest, total);
break;
int highest(int num1, int num2);
{
if (num1 < num2)
return (num2);
if (num1 > num2)
return (num1);
}

case '2':
scanf("%d", &x1);
int multiray[12];
for(x = 0;x < 13; x++)
multiray[x] = x;
(x2 = x*x1);
for(x = 0;x < 13; x++)
printf("%d x %d = %d\n", multiray[x], x1, x2);

break;

default:
printf("\nInvalid selection\n");
}						// end switch

getch();
return 0;
}```

2. Code:
`int highest(int, int);`
Here you're declaring a prototype for a function, NOT calling a function. You should put this above main, then take your function definition OUTSIDE of the switch statement and put it below main.

Total should be placed at 0, not -1, I think.

Code:
`for(x = 0;x < 13; x++)`
Your test condition must be x < 12, since 12 is the size of the array and 11 is the highest valid index.

I suspect your problems stem from these two, but there may also be some others since I just did a quick scan of the code.

3. What are you expecting the brackets to do here?:
(x2 = x*x1);

4. I should optimize your case statement for option 2 to build out your multiplication table as such:

Code:
```for(x = 0; x < 13; x++)
{
multiray[x] = x * x1;
printf("%d x %d = %d\n", x, x1, multiray[x]);
}
break;```
You should always limit your need for for-loops and variables when possible.

5. Originally Posted by MacNilly
Code:
`int highest(int, int);`
Here you're declaring a prototype for a function, NOT calling a function. You should put this above main, then take your function definition OUTSIDE of the switch statement and put it below main.
Ah, not only that, but the OP is also defining a new function inside a function.
The entire function should be moved outside main and the ; after the parameter list should be removed.
And also to add to what MacNilly mentioned, add the names of the parameters back into that prototype.
http://apps.sourceforge.net/mediawik...arameter_names