void input (int array[20]); //Used when user inputs the numbers.
void calculate(int array[20], int *pairs); //Used to calculate the matches.
void output(int *pairs); //Used to output the number of pairs.
int main(void)
{
int array[20];
char quit;
start:
int pairs = 0;
input(array);
calculate(array,&pairs);
output(&pairs);
//Ask the user if they want to exit
printf("\nWould you like to continue testing my project, or exit?");
printf("\nTo exit input: 'N' or 'n'. To continue testing input anything else.");
//store their input in variable: exit
scanf("%s",&quit);
//If they want to exit...
if (quit == 'N' || quit == 'n')
{
//exit,
exit;
}
//otherwise,
else
{
//clear the screen
system("cls");
//and go back to the start.
goto start;
}
}
void calculate(int array[20], int *pairs)
{
int counter = 0;
for (counter;counter<19;counter++)
{
if (array[counter] == array[counter+1])
*pairs+=1;
}
}
void output(int *pairs)
{
printf("Number of pairs: [%i]\n", *pairs);
}
-Look at item 1 in the array
-Compare to item 2 in the array, if they are the same
-Compare to item 3 in the array, if they are the same, that's a triplet.
-Look at item 2 in the array,
-Compare to item 3 in the array, if they are the same
-Compare to item 4 in the array, if they are the same, that's a triplet
etc...
Also, you should not for any reason be using goto in this program. I strongly suggest removing the goto call. You should be using control loops (do...while, while, for etc...) and functions to control program flow.
Firstly, when you describe your problems, can you give as much detail as possible? Saying "it doesn't work" isn't very helpful. Saying "it doesn't work and x happens instead" or "it doesn't work and my compiler gives whatever error" is very much more helpful. ;) So why exactly is it not working or what is or is not happening?
I'm also confused as to why you are using <iostream> but not using std::cout and std::cin ? Either do C++ OR C, don't mix them.
In function `void input(int*)':
line 28 `trip' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
In function `void calculate(int*, int*)':
line 40 cannot convert `int**' to `int*' for argument `1' to `void output(int*)'
Well, the first of those errors is self-explanatory. As I've already pointed out, tripis undefined in your input function. Did you mean to pass it in as an argument?
At line 40, you're attempting to pass the address of trip into output. But you've already defined trip as being a pointer to an int, i.e. an int* (see line 31), so the address of it is a pointer to a pointer to an int, i.e. an int**.
There's no need to pass the address of trip here - just pass trip itself, because it's already a pointer.