challenge 2 guessing game

0 Amit Vikram · June 24, 2015
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

int main()
{
int i;
int diceroll;
int dice2;
int dicethrow;
int total;
int answer;
int totals;


for(i=0; i<1; i++){

    srand(time(NULL));

    diceroll = ( rand()%6 )+ 1;
    printf(" %d \n", diceroll);

    dice2 = ( rand()%6 )+ 1;
    printf(" %d \n", dice2);


    dicethrow = ( rand()%6 )+ 1;
    printf(" %d \n", dicethrow);

    total = diceroll + dice2 + dicethrow;
    printf("total is : %d \n", total);
    puts("predict if next total will be high or low");
    puts(" high is above 10 and low is below 10 ");
    puts(" press 1 for high and 2 for below");
    scanf(" %d \n", &answer);


    diceroll = ( rand()%6 )+ 1;
    printf(" %d \n", diceroll);

    dice2 = ( rand()%6 )+ 1;
    printf(" %d \n", dice2);


    dicethrow = ( rand()%6 )+ 1;
    printf(" %d \n", dicethrow);

    totals = diceroll + dice2 + dicethrow;
      printf("total is : %d \n", totals);


    if((totals>10) && (answer==1)){printf("good job");}
    if((totals<10) && (answer==2)){printf("good job");}
    if((totals<10) && (answer==1)){printf("bad job");}
    if((totals>10) && (answer==2)){printf("bad job");}
    if(totals==10){printf("neither good nor bad");}



}

return 0;
}

Post a Reply

Replies

Oldest  Newest  Rating
+1 William Frost · June 26, 2015
First of all, use the code tag. secondly, where is the bloody comments?
  • 1

C

107,220 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator