Rock Paper Scissors Game | C Programming Example

  Рет қаралды 10,540

Portfolio Courses

Portfolio Courses

Күн бұрын

Пікірлер: 30
@charlotte264
@charlotte264 Жыл бұрын
How can i make this games play over and over again. Because when it run, it can only play 2,3 rounds
@PortfolioCourses
@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 . :-)
@asrithpolur8583
@asrithpolur8583 2 жыл бұрын
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?
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
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! 🙂
@asrithpolur8583
@asrithpolur8583 2 жыл бұрын
@@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.
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
@@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.
@rakurame6990
@rakurame6990 3 жыл бұрын
Can we also use enum for defining the values for rock, paper and scissors?
@PortfolioCourses
@PortfolioCourses 3 жыл бұрын
Yes, if we did it might look something like this: enum Throw {Rock = 1, Paper = 2, Scissors = 3};
@rakurame6990
@rakurame6990 3 жыл бұрын
@@PortfolioCourses Got it.
@Dad-Seven
@Dad-Seven 2 жыл бұрын
Amazing tutorial
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Thank you! :-)
@mohammedahmad1650
@mohammedahmad1650 2 жыл бұрын
@portfolio courses. How could I use the formula using math and have variations of 101? Kind Regards
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
I'm sorry Mohammed I don't understand the question you're asking. 😞 Which formula? And what is 101 referring to?
@mohammedahmad1650
@mohammedahmad1650 2 жыл бұрын
??
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
@@mohammedahmad1650 Can you try to explain the question you have again?
@mohammedahmad1650
@mohammedahmad1650 2 жыл бұрын
@@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
@mohammedahmad1650
@mohammedahmad1650 2 жыл бұрын
@@PortfolioCourses also how would we handle 101 gestures Kind Regards
@justaperson866
@justaperson866 2 жыл бұрын
Can you also put a counter so that it tracks how many wins and losses you have in a while loop?
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
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. 🙂
@justaperson866
@justaperson866 2 жыл бұрын
@@PortfolioCourses thanks man i needed help with my c programming homework
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
@@justaperson866 Good luck! 😀
@johnemmanuelbontilao471
@johnemmanuelbontilao471 2 жыл бұрын
Sir I don't know how to thank you for this. Ahm do you have flowchat for this? I badly need it
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You're welcome! :-) I don't have a flowchart, but it might be a good exercise to try to produce it from the code.
@lidk7736
@lidk7736 2 жыл бұрын
may i ask what app is this
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
The program itself was written with Xcode on a Mac. The game is 'rock paper scissors': en.wikipedia.org/wiki/Rock_paper_scissors.
@sushantanil35
@sushantanil35 2 жыл бұрын
Error my
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Was there more to this comment Anil? I'm not sure I understand. :-)
you will never ask about pointers again after watching this video
8:03
Arenas, strings and Scuffed Templates in C
12:28
VoxelRifts
Рет қаралды 101 М.
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН
黑天使被操控了#short #angel #clown
00:40
Super Beauty team
Рет қаралды 61 МЛН
Naming Things in Code
7:25
CodeAesthetic
Рет қаралды 2,3 МЛН
one year of studying (it was a mistake)
12:51
Jeffrey Codes
Рет қаралды 204 М.
My 10 “Clean” Code Principles (Start These Now)
15:12
Conner Ardman
Рет қаралды 318 М.
String In Char Array VS. Pointer To String Literal | C Programming Tutorial
9:58
Get Better At Music By Practicing Less
15:06
Brad Harrison Music
Рет қаралды 1,1 МЛН
15 Years Writing C++ - Advice for new programmers
4:04
SyncMain
Рет қаралды 1,3 МЛН
Rust for the impatient
10:43
No Boilerplate
Рет қаралды 769 М.
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
Writing Code That Runs FAST on a GPU
15:32
Low Level
Рет қаралды 577 М.
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН