Long Programming Exercise 1 Write a program to play a dice g
Solution
#include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
int main()
 {
 int tokens; //variable for storing tokens value
 int wager; //variable for storing wager value
 int computer_diceface_value; //variable for storing computer_diceface_value value   
 int user_diceface_value; //variable for storing user_diceface_value value
 int wish; //variable for storing wish of the user i.e whether he wants to play or not
 srand(time(NULL)); //seeding random number
 printf(\"It is a dice game with computer,the computer rolls a dice and you roll a dice \ \"); //explaining the //game to user
 printf(\"If computer\'s dice is greater in value than yours,the computer wins,Nobody wins a tie \  \");
 printf(\"You want to play this game or not if yes then either enter \'1\' or \'y\',if not please enter \'0\' or \'n\'. \ \");
 wish=getchar();
 if(wish==\'y\'|| wish==\'1\') //if user wants to play
 {while(wish==\'y\'|| wish==\'1\')
 {int tokens=100;
 printf(\"Please enter the wager,wager must be greater than 0 and less than equal to tokens i.e 100 \ \"); //asking the value of wager from user
 scanf(\"%d\",&wager);
 while(wager<=0 || wager > tokens){
 printf(\"Please enter the valid wager which must be greater than 0 and less than equal to tokens i.e 100 \  \"); //asking for the correct value of wager
 scanf(\"%d\",&wager);}
 while(tokens != 0 || tokens != 200) //while token is not equal to 0 or 100 game will be in //continue mode
 {
 printf(\"Rolling the dice for the user \ \");
 user_diceface_value=(rand() % 6 ) + 1;
 printf(\"Rolling the dice for the computer \ \");
 computer_diceface_value=(rand() % 6 ) + 1;
 printf(\"Your dice value %d \  \", user_diceface_value);
 printf(\"Computer\'s dice value %d \  \", computer_diceface_value);
 if(computer_diceface_value > user_diceface_value ) //computer wons
 tokens=tokens-wager;
 else if(computer_diceface_value < user_diceface_value) //user wons
 tokens=tokens+wager;
            else //handaling the case of tie
            tokens=tokens;
 }
 if(tokens==200) //tokens=200,user won
 {printf(\"You won the dice game \ \");
 printf(\"You want to play this game or not if yes then either enter \'1\' or \'y\',if not please enter \'0\' or \'n\'. \ \");
 wish=getchar();
 }
 else
 {printf(\"You lost the dice game\");
 printf(\"You want to play this game or not if yes then either enter \'1\' or \'y\',if not please enter \'0\' or \'n\'. \ \");
 wish=getchar();
 }
 
 }
 
   
   
 }
 else //if user doesnot want to play exit the game.
 exit(1);
   
return 0;
 } //end of code
****************Output***************
 It is a dice game with computer,the computer rolls a dice and you roll a dice   
 If computer\'s dice is greater in value than yours,the computer wins,Nobody wins a tie   
 You want to play this game or not if yes then either enter \'1\' or \'y\',if not please enter \'0\' or \'n\'.
 1
 Please enter the wager,wager must be greater than 0 and less than equal to tokens i.e 100
 2
 Rolling the dice for the user   
 Rolling the dice for the computer   
 Your dice value 5   
 Computer\'s dice value 4   
 Your dice value 3
 Computer\'s dice value 6
 
 You lost the dice gameYou want to play this game or not if yes then either enter \'1\' or \'y\',if not please enter \'0\' or \'n\'.
*******************Output***************
Please let me know in case you have any doubt.


