So I was just think of how to do it and gave it a go. Heres what I got, It works fine, I just want to know if there would be a better way of doing it, a more efficient way so there isn't as many if statements:
Code:#include <stdio.h> #include <windows.h> #include <time.h> #include <stdlib.h> main() { int iSelection = 0; int iRandom = 0; srand(time(0)); iRandom = (rand() % 3) + 1; printf("\tRock, Paper, Scissors!\n"); printf("\n1\tRock\n"); printf("2\tPaper\n"); printf("3\tScissors\n"); printf("\nPlease enter a selection: "); scanf("%d", &iSelection); if (iSelection < 1 || iSelection > 3) { printf("\nPlease enter a valid selection!\n"); } if (iSelection == 1 && iRandom == 1) { printf("\nYou selected %d\n", iSelection); printf("\nYou opponent selected %d\n", iRandom); printf("\nIt's a tie!\n"); } if (iSelection == 1 && iRandom == 2) { printf("\nYou selected %d\n", iSelection); printf("\nYou opponent selected %d\n", iRandom); printf("\nYou Lose!\n"); } if (iSelection == 1 && iRandom == 3) { printf("\nYou selected %d\n", iSelection); printf("\nYou opponent selected %d\n", iRandom); printf("\nYou Win!\n"); } if (iSelection == 2 && iRandom == 1) { printf("\nYou selected %d\n", iSelection); printf("\nYou opponent selected %d\n", iRandom); printf("\nYou Win!\n"); } if (iSelection == 2 && iRandom == 2) { printf("\nYou selected %d\n", iSelection); printf("\nYou opponent selected %d\n", iRandom); printf("\nIt's a tie!\n"); } if (iSelection == 2 && iRandom == 3) { printf("\nYou selected %d\n", iSelection); printf("\nYou opponent selected %d\n", iRandom); printf("\nYou Lose!\n"); } if (iSelection == 3 && iRandom == 1) { printf("\nYou selected %d\n", iSelection); printf("\nYou opponent selected %d\n", iRandom); printf("\nYou Lose!\n"); } if (iSelection == 3 && iRandom == 2) { printf("\nYou selected %d\n", iSelection); printf("\nYou opponent selected %d\n", iRandom); printf("\nYou Win!\n"); } if (iSelection == 3 && iRandom == 3) { printf("\nYou selected %d\n", iSelection); printf("\nYou opponent selected %d\n", iRandom); printf("\nIt's a tie!\n"); } Sleep(5000); }



LinkBack URL
About LinkBacks


