Freaky overloaded functions for Lottery Program VERY HARD

Needing a little assist if anyone knows how to do this? I have my homework complete and working great except for the wording in report. 5 random in array and 5 int in array from user input. Compared and report showing number matched and elements that matched.

The report should look like this.


There are two matching digits, elements 2 and 4.
winningDigits 7 4 9 1 3
player        4 2 9 7 3


But is looking like this:


Enter number 0 to 9 for:
Lotto pick 1 - 7
Lotto pick 2 - 8
Lotto pick 3 - 2
Lotto pick 4 - 8
Lotto pick 5 - 5

There are four matching digits, elements 0, 1, 2, 3,
Winning Digits 7 8 2 8 7
Player         7 8 2 8 5


The issue is the end of first sentence in report. It should end with 'and 3' but I am having trouble with this part. All code included below and some comments in code showing overloaded functions that I would like to use. This would resolve the issue with first line but, I'm not sure how to keep track of the matching values and pass them to the function.

These are my overloaded functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void outputCorrect()	//0
{int countCorrect = 0; cout << "There are zero matching digits.\n" };

void outputCorrect(int zero)	//1
{int countCorrect = 1; cout << "There are " << countCorrect << " matching digits, elements " << zero};

void outputCorrect(int zero, int one)	//2
{int countCorrect = 2; cout << "There is " << countCorrect << " matching digit, element " << zero << ", " << one}

void outputCorrect(int zero, int one, int two)	//3
{int countCorrect = 3; cout << "There are " << countCorrect << " matching digits, elements " << zero << ", " << one << ", " << two}

void outputCorrect(int zero, int one, int two, int three)	//4
{int countCorrect = 4; cout << "There are " << countCorrect << " matching digits elements, " << zero << ", " << one << ", " << two << ", " << three}

void outputCorrect(int zero, int one, int two, int three, int four)	//5
{int countCorrect = 5; cout << "There are " << countCorrect << " matching digits elements, " << zero << ", " << one << ", " << two << ", " << three << ", " << four}


This is code to compare data; but need assist in this loop.

1
2
3
4
5
6
7
8
9
10
11
12
for (index = 0; index < SIZE; index++)
    {
        if (winningDigits[index] == player[index])
		{
			count++;
			//number = winningDigits[index];
			cout << index << (comma = (count > 0) ? ", " : "") ;

		};

    };


Not going to include all code after all because this assignment is not due and don't want to provide all. I think there is enough for solution.

Thanks
Instead of overloading all those functions, this would be easily accomplished with 4 for loops.

The solution is not scalable - what if you had more numbers - you would need to add more functions. This is not good programming practice. It also looks as though you have a variable for each number.

So you could have one for loop that assigns random numbers to a vector. Then another to get the users selected numbers. The last one to compare them. A final one to print out the results.

Some other style points:

- Don't put multiple statements on one line.
-If you have a long cout statement - build it up in stages - it doesn't have to all be on one line o f code. What if you had to print out 300 fields for a database - are you going to have statement that is 5000 chars long?

HTH
Very good point. Will work on that.

Thanks
The formatting is only this way now so I can see it easily when scrolling, would not leave it that way... Thanks again
Topic archived. No new replies allowed.