Hello all I have a problem with a program that I have to write. I started it already but I cannot finish it. I don't know where to go from where I am. Any help would be greatly appreciated. Here is the description of what I have to do:
Write a program which will get 10 random numbers onto one array1 of size 10. Get 10 more random numbers and place them in array2 of size 10. The range of the numbers should be 1-10 only (no zero).
Ask for the names of two players.
The first array is for first player. The second array is for second player. You will compare the numbers for each person and whoever has the bigger number wins. You will compare the same element in the array for each player, so comparing element 0 from array1 with element 0 from array2. Keep count of how many wins and display the persons name of the one who won. *in case of a tie, keep rolling a random number for each player and compare to see who wins...they may tie again so keep going till someone wins.
for (int a=0; a<10; a++) {
// three possibilities here:
// 1. array1[a] < array2[a]
// 2. array2[a] < array1[a]
// 3. tie
// Thus, the win count of at most one player can increment by one
}
You obviously have to have the two win counters.
In case of final tie do a loop that rolls new pairs and updates the win counters.
Write a program which will get 10 random numbers onto one array1 of size 10. Get 10 more random numbers and place them in array2 of size 10
You will compare the numbers for each person and whoever has the bigger number wins. You will compare the same element in the array for each player, so comparing element 0 from array1 with element 0 from array2. Keep count of how many wins and display the persons name of the one who won.
Tip:
in case of a tie, keep rolling a random number for each player and compare to see who wins...they may tie again so keep going till someone wins.
//...
cout<<"Round["<<i+1<<"]: "<<array1[i]<<" to "<<array2[i]<<" = ";
if(array1[i]>array2[i])
{
++count1;
cout<<player1<<" won the round!"<<endl;
}
elseif(array1[i]<array2[i])
{
++count2;
cout<<player2<<" won the round!"<<endl;
}
else
{
--i;//Redo this test.
cout<<"There was a tie, Rematch!"<<endl;
}
//...
Please enter player ones name: Bob
Please enter player twos name: Steve
The winner per element:
Round[1]: 4 to 3 = Bob won the round!
Round[2]: 7 to 10 = Steve won the round!
Round[3]: 3 to 10 = Steve won the round!
Round[4]: 4 to 6 = Steve won the round!
Round[5]: 2 to 10 = Steve won the round!
Round[6]: 3 to 9 = Steve won the round!
Round[7]: 2 to 9 = Steve won the round!
Round[8]: 3 to 1 = Bob won the round!
Round[9]: 9 to 2 = Bob won the round!
Round[10]: 6 to 4 = Bob won the round!
Bob won 4 times.
Steve won 6 times.
The winner is Steve
Process returned 0 (0x0) execution time : 4.228 s
Press any key to continue.
Keep count of how many wins and display the persons name of the one who won. * in case of a tie, ...
To me that is a bit ambiguous. Do we want an overall winner or a winner for each element/round?
If the overall is all that is required, then max(count1,count2) is all that is interesting and single elements can tie. We thus roll 10 pairs and then an unknown number of additional pairs, if the first 10 sum up to a tie.
If the overall is not required to win, then we can limit to creating 10 pairs (rounds), where each has a winner (and show each). Dput's loop does that. This can result in overall tie (count1==count2==5).
In principle, one could enforce that both each round has a winner and that the whole match has a winner. It gets real tricky if the number of reported rounds must remain 10.
Yes, as kesk said, you need to ask your professor: what to do in an even that both players have the same number of wins.
Personally, I would:
Prompt that there were no winners, because there weren't.
OR
Have a "death match", because a winner is necessary.
OR
do-A-Work-Around and Display the first person to achieve at least 5 wins.
None of which may be a part of this programs design.
in case of a tie, keep rolling a random number for each player and compare to see who wins...they may tie again so keep going till someone wins
But if we assume that the continuous combating of numbers, refer to round wins and absolute win, then a "death match" may fit the description.