Challenge#2 Done

0 laith elhamwi · December 28, 2014
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <string.h>
int main()
{
  int a;
  int dice1;
  int sum1=0;
  int b;
  int sum2=0;
  int dice2;
  char c;

  printf("Lets play \n");
  printf("I am going to throw the dice three times \n and i will collect the total sum of the numbers that show. ");
  printf("\n Your job is to guess if the next number that appears is higher , lower or equal to the first number. \n");
for(a = 0 ;a < 3; a++)
{
    dice1=(rand()%6)+1;

    sum1 += dice1;
}
printf("The number is :%d \n",sum1);

printf ("Enter your guess: (h/l/e)\n");
scanf(" %c",&c);
if(c =='h')
{
    c ='h';
}
else if(c =='l')
{
    c='l';
}
else if(c =='e')
{
    c ='e';
}
else
{
 
    printf("Error");
}
for(b = 0; b < 3; b++)
{
    dice2=(rand()%6)+1;
    sum2 += dice2;
}
printf("The number is :%d \n",sum2);

if(sum2>sum1 && c=='h')
{
    printf("Good Guess");
}
else if(sum2<sum1 && c=='l')
{
    printf("Good Guess");
}
else if(sum1==sum2 && c=='e')
{
    printf("Good Guess!");
}
else
{
    printf("Loser (bad luck)");
}
   return 0;
}


Post a Reply

Replies

Oldest  Newest  Rating
-1 Nishant Tadvi · December 28, 2014
I think you has took long method. Try to make small as much as you can. otherwise it is perfect.
  • 1

C

107,324 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator