When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
34 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
string WhoWonTheRound(stRoundInfo RoundInfo)
{
if (RoundWinner(RoundInfo) == enWinner::Player)
{
system("color 2F");
return "[Player]";
}
else if (RoundWinner(RoundInfo) == enWinner::Computer)
{
system("color 4F");
return "[Computer]";
}
else if (RoundWinner(RoundInfo) == enWinner::Draw)
{
system("color 6F");
return "[No Winner]";
}
}
stRoundInfo FillRoundInfo(short UserChoice)
{
stRoundInfo RoundInfo;
RoundInfo.PlayerChoice = (enChoice)UserChoice;
RoundInfo.ComputerChoice = GetComputerChoice();
RoundInfo.RoundWinner = WhoWonTheRound(RoundInfo);
return RoundInfo;
}
void RoundInfoResults(stRoundInfo RoundInfo)
{
cout << "Player1 Choice : " << RoundInfo.PlayerChoice << "\n";
cout << "Computer Choice : " << RoundInfo.ComputerChoice << "\n";
cout << "Round Winner : " << RoundInfo.RoundWinner;
}
void GameRound(short HowManyRounds)
{
char PlayAgain = ',';
do {
for (short GameRound = 1; GameRound <= HowManyRounds; GameRound++)
{
cout << "\nRound [" << GameRound << "] begins: \n";
short UserChoice = ReadPlayerChoice();
cout << "\n\n______________________Round[" << GameRound << "]______________________\n\n";
RoundInfoResults(FillRoundInfo(UserChoice));
cout << "\n\n______________________________________________________________________\n\n";
}
cout << "Do you want to play again (Y/N) ? ";
cin >> PlayAgain;
} while (PlayAgain == 'Y' || PlayAgain == 'y');
}
int main()
{
srand((unsigned)time(NULL));
short HowManyRounds = ReadNumberInRange(1, 10);
GameRound(HowManyRounds);
return 0;
}```
sorry didn't add the other part
You’re calling grtcomputerchoice multiple times
Assign it to a short before you use it
ah ok, should i assign it in the WhoWonTheRound() ?
Within RoundWinner
Very first thing is assign it to a short
Then use the local variable instead of the function call
is it better to assign it whitin the main() or within RoundWinner() ?
RoundWinner, as it changes each time you call it
Ideally you’d pass in both the computer and user choices in as parameters
i already passed the struct, should i just change GetComputerChoice() into RoundInfo.ComputerChoice ?
Sure yeah try that
Dw
should i keep dividing the program into functions and procedures that perform one task just like this ? or only when it's necessary? because sometimes i'm getting lost
i just started learning
I think you’re subdividing a bit too much
It looks slightly over engineered, like that RoundInfo struct doesn’t seem wholly necessary to me
You have the right idea tho of subdividing
@cold adder Has your question been resolved? If so, type !solved :)
actually my idea was to create 2 struct while one stores only the roundInfo and the other one is a nested struct that stores the GameResult ( for ex the score of the game ect..)
i just thought that maybe it will make the program easier to read
Less typing is generally easier to read
Ok well i wll try not to overcomplicate things XD
thank u for the help
have a good day
!solved
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity
Np gl