{"id":4150,"date":"2023-03-08T18:16:25","date_gmt":"2023-03-08T18:16:25","guid":{"rendered":"https:\/\/studiotechx.com\/projects\/?p=4150"},"modified":"2023-03-08T18:16:58","modified_gmt":"2023-03-08T18:16:58","slug":"rock-paper-scissor","status":"publish","type":"post","link":"https:\/\/studiotechx.com\/projects\/rock-paper-scissor\/","title":{"rendered":"Rock-Paper-Scissor in C"},"content":{"rendered":"\n<p>Cli Based Rock Paper Scissor Game<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h>\n#include &lt;stdlib.h>\n#include &lt;time.h>\n\n#define ROCK 1\n#define PAPER 2\n#define SCISSORS 3\n\nint main() {\n    int playerScore = 0;\n    int computerScore = 0;\n    int rounds = 0;\n\n    printf(\"Welcome to Rock-Paper-Scissors game!\\n\\n\");\n\n    while(1) {\n        int playerMove;\n        printf(\"Enter your move (1 = Rock, 2 = Paper, 3 = Scissors, 0 = Quit): \");\n        scanf(\"%d\", &amp;playerMove);\n\n        if (playerMove == 0) {\n            break;\n        }\n\n        if (playerMove &lt; 1 || playerMove > 3) {\n            printf(\"Invalid move! Please try again.\\n\");\n            continue;\n        }\n\n        int computerMove = rand() % 3 + 1;\n\n        printf(\"You played: \");\n        switch(playerMove) {\n            case ROCK:\n                printf(\"Rock\\n\");\n                break;\n            case PAPER:\n                printf(\"Paper\\n\");\n                break;\n            case SCISSORS:\n                printf(\"Scissors\\n\");\n                break;\n        }\n\n        printf(\"Computer played: \");\n        switch(computerMove) {\n            case ROCK:\n                printf(\"Rock\\n\");\n                break;\n            case PAPER:\n                printf(\"Paper\\n\");\n                break;\n            case SCISSORS:\n                printf(\"Scissors\\n\");\n                break;\n        }\n\n        if (playerMove == computerMove) {\n            printf(\"It's a tie!\\n\");\n        } else if (playerMove == ROCK &amp;&amp; computerMove == SCISSORS ||\n                   playerMove == PAPER &amp;&amp; computerMove == ROCK ||\n                   playerMove == SCISSORS &amp;&amp; computerMove == PAPER) {\n            printf(\"You win this round!\\n\");\n            playerScore++;\n        } else {\n            printf(\"Computer wins this round!\\n\");\n            computerScore++;\n        }\n\n        rounds++;\n        printf(\"Current score: You %d - %d Computer\\n\\n\", playerScore, computerScore);\n    }\n\n    printf(\"\\nFinal score: You %d - %d Computer\\n\", playerScore, computerScore);\n    printf(\"Total rounds played: %d\\n\", rounds);\n\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"Cli Based Rock Paper Scissor Game\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":"","csco_singular_sidebar":"","csco_page_header_type":"","csco_appearance_grid":"","csco_page_load_nextpost":"","csco_post_video_location":[],"csco_post_video_location_hash":"","csco_post_video_url":"","csco_post_video_bg_start_time":0,"csco_post_video_bg_end_time":0},"categories":[19],"tags":[],"aioseo_notices":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/posts\/4150"}],"collection":[{"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/comments?post=4150"}],"version-history":[{"count":2,"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/posts\/4150\/revisions"}],"predecessor-version":[{"id":4153,"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/posts\/4150\/revisions\/4153"}],"wp:attachment":[{"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/media?parent=4150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/categories?post=4150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/tags?post=4150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}