Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- #include <math.h>
- int main()
- {
- int i;
- int dice1;
- int dice2;
- int dice3;
- int sum1;
- int sum2;
- char input;
- int input1; // this should be a int, not a char
- srand(time(NULL));
- printf("****Dice roll game with 3 dices****\n\n");
- for(i=0; i<1; i++){
- dice1 = (rand()%6) +1;
- printf("dice1 = %d\n", dice1);
- dice2 = (rand()%6) +1;
- printf("dice2 = %d\n", dice2);
- dice3 = (rand()%6) +1;
- printf("dice3 = %d\n", dice3);
- sum1 = dice1+dice2+dice3;
- }
- printf("The total from 3 dices is %d \n\n", sum1);
- printf("What do you think your next roll will be higher(h),lower(l) or same(s) as the current total? \n\n");
- do{
- printf("Enter (h),(l) or (s) to continue \n\n");
- scanf(" %c", &input); //add a space between the quotes like " %c" not "%c"
- if( (input == 'l') || (input == 'h') || (input == 's') ){
- input1 = 1;
- }else{
- input1 = 0;
- printf("please read the text and try again\n\n");
- }
- }while(input1!=1);
- for(i=0; i<1; i++){
- dice1 = (rand()%6) +1;
- printf("dice1 = %d\n", dice1);
- dice2 = (rand()%6) +1;
- printf("dice2 = %d\n", dice2);
- dice3 = (rand()%6) +1;
- printf("dice3 = %d\n", dice3);
- }
- sum2 = dice1+dice2+dice3;
- if((sum1<sum2) && (input == 'h')){
- printf("Congratz you guessed right total %d\n", sum2);
- }else if ((sum1>sum2) && (input == 'l')){
- printf("Congratz you guessed right total %d\n", sum2);
- }else if ((sum1==sum2) && (input == 's')){
- printf("Congratz you guessed right total %d\n", sum2);
- }
- else{
- printf("you loose your total is %d\n", sum2);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement