What is wrong with my code?

I've been working on this assignment for my programming class, but my last module is giving me issues. My brain is a bit fried and I just don't see whats wrong. Any help please?


This is my code:

#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;


void getNums(int[], int);
void lotNums(int[], int);
int matchNums(int[], int[], int);
void results(int[], int[], int);


int main()
{
//V&C
const int SIZE = 5;
int lottery[SIZE];
int userNums[SIZE];
char choice;

do
{
// Input
getNums(userNums, SIZE);

// Generate lottery #'s
lotNums(lottery, SIZE);

// Compare array
matchNums(lottery, userNums, SIZE);

// Output
results(lottery, userNums, SIZE);

//Play again?
cout<<"Would you like to play again? (Y/N)"<<endl;
cin>>choice;

} while ((choice == 'Y') || (choice == 'y'));
return 0;
}

void getNums(int userNums[], int SIZE)
{
int counter;

cout << "Please enter " << SIZE << " numbers for your chance to win.\n(Numbers must be from 0 - 9)"<<endl;

for(counter = 0; counter < SIZE; counter++)
{
cin >> userNums[counter];
}
}

void lotNums(int lottery[], int SIZE)
{
int seed = 1;
srand(seed);

for (int i = 0; i < SIZE; i++)
{
int randNum = rand() % 10;
lottery[i] = randNum;
}

}

int matchNums(int lottery[], int userNums[], int SIZE)
{
int match = 0;

cout<<"The Lottery numbers are: "<<endl;
for(int i=0; i<5; i++)
{
cout<<lottery[i];
}

cout<<"Your numbers are: "<<endl;
for(int i=0; i<5; i++)
{
cout<<userNums[i];
}

for(int i=0; i<5; i++)
{
for(int j=0; j<5; j++)
{
if(userNums[i] == lottery[j])
{
match++;
}
}
cout<< "There are "<<match<<" matches."<<endl;
}

void results(int lottery[], int userNums[], int SIZE)
{
int aEqual;

if(aEqual = false)
cout << "Sorry, your numbers were lottery numbers were not the winning numbers.\n";
else
cout << "Congratulations! You won!.\n";

}
I didn't check anything else yet but the first thing I see is
if(aEqual = false)
Change that to ==.

It also seems like you are missing a closing bracket for the matchNums function. (Which isn't returning a value so shouldn't be marked as int).

Your results function is checking against the local variable aEqual which was never given a value, it should be based on how many matches were found.

Finally your matching numbers loop seems to count the same numbers every time (so if 1 is in both sets, it will be counted 5 times). You will need to rewrite that somehow so it only counts it once per appearance.
Last edited on
Yes!! Thank you! I got it working. I ended up just merging the last 2 functions, matchNums and results.
Topic archived. No new replies allowed.