How can i make this games play over and over again. Because when it run, it can only play 2,3 rounds
@PortfolioCourses Жыл бұрын
The game in this video is setup so that it is played until there is no draw. So it could be 1,2,3,... or more rounds technically. The code for this video is here: github.com/portfoliocourses/c-example-code/blob/main/rock_paper_scissors.c. To make it play over and over again, you could wrap the entire do-while loop in a loop like this: while (true) { ... do while loop ... } You might want to allow the user to quit though eventually. To do that, you could wrap the do-while loop in another do-while loop with another menu. This video shows how to make that sort of menu that eventually allows the user to quit when they decide to: kzbin.info/www/bejne/m4TXc415iLFgnbM . :-)
@asrithpolur85832 жыл бұрын
if i added a score counter as a int variable, how would i make it so that the program would stop in best out of 3 situation and print out the winner?
@PortfolioCourses2 жыл бұрын
Good question Asrith. :-) I can try to give you some advice. I think if you wanted to make it a 'best out of 3' situation then you would need to counters... one for the AI wins and one for the player wins. So maybe something like: int player_wins = 0; int ai_wins = 0; Then you would need to increment the player_wins and ai_wins variables in the if-else if conditions where that player wins. So where it says "you lose" you would need to increment ai_wins (ai_wins++) and where it says "you win" you would need to increment player_wins (player_wins++). This would involve creating a block of instructions for each if-else-if case with { ... statements ... } as right now it only executes one printf() statement in these cases and so there is no block with curly braces. If you want to execute multiple statements you would need curly braces and a block for each if-else-if case. You would then need to surround the do-while loop with another loop. The other loop should stop when either ai_wins == 2 or player_wins == 2 as that would mean the game is over. You could then have an if-else-structure at the bottom of the program that outputs who won the best 2 out of 3 based on whether ai_wins == 2 or player_wins == 2. Hopefully this helps! 🙂
@asrithpolur85832 жыл бұрын
@@PortfolioCourses Thank you for that. Are you able to show a brief example of how exactly i would create multiple blocks of instructions for the if-elseif statements.
@PortfolioCourses2 жыл бұрын
@@asrithpolur8583 If you want to have a multiple statements it looks like this: if (x > 5) { i++; j++; } else if (x < 10) { i--; j--; } You need to use { ... } like in the above examples.
@rakurame69903 жыл бұрын
Can we also use enum for defining the values for rock, paper and scissors?
@PortfolioCourses3 жыл бұрын
Yes, if we did it might look something like this: enum Throw {Rock = 1, Paper = 2, Scissors = 3};
@rakurame69903 жыл бұрын
@@PortfolioCourses Got it.
@Dad-Seven2 жыл бұрын
Amazing tutorial
@PortfolioCourses2 жыл бұрын
Thank you! :-)
@mohammedahmad16502 жыл бұрын
@portfolio courses. How could I use the formula using math and have variations of 101? Kind Regards
@PortfolioCourses2 жыл бұрын
I'm sorry Mohammed I don't understand the question you're asking. 😞 Which formula? And what is 101 referring to?
@mohammedahmad16502 жыл бұрын
??
@PortfolioCourses2 жыл бұрын
@@mohammedahmad1650 Can you try to explain the question you have again?
@mohammedahmad16502 жыл бұрын
@@PortfolioCourses if we had a version of rock paper scissors and 4 or 5 other gestures how could we come up with a formula that handles 7 gestures
@mohammedahmad16502 жыл бұрын
@@PortfolioCourses also how would we handle 101 gestures Kind Regards
@justaperson8662 жыл бұрын
Can you also put a counter so that it tracks how many wins and losses you have in a while loop?
@PortfolioCourses2 жыл бұрын
Yes, you could create two new variables before the loop for wins and losses, both of them could be ints. And then inside the loop, for each if-statement branch with a loss you could increment the losses variable, and for each branch with a win you increment the wins variable. And then you could output both variables after the loop. 🙂
@justaperson8662 жыл бұрын
@@PortfolioCourses thanks man i needed help with my c programming homework
@PortfolioCourses2 жыл бұрын
@@justaperson866 Good luck! 😀
@johnemmanuelbontilao4712 жыл бұрын
Sir I don't know how to thank you for this. Ahm do you have flowchat for this? I badly need it
@PortfolioCourses2 жыл бұрын
You're welcome! :-) I don't have a flowchart, but it might be a good exercise to try to produce it from the code.
@lidk77362 жыл бұрын
may i ask what app is this
@PortfolioCourses2 жыл бұрын
The program itself was written with Xcode on a Mac. The game is 'rock paper scissors': en.wikipedia.org/wiki/Rock_paper_scissors.
@sushantanil352 жыл бұрын
Error my
@PortfolioCourses2 жыл бұрын
Was there more to this comment Anil? I'm not sure I understand. :-)