Challenge 2

+1 Manisha Kohli · October 13, 2015
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
int main()
{
//roll 3 dice

int a=0,b=0,i,diceRoll;
char choice[1];

srand(time(0));
for(i=0;i < 3;i++)
{
  diceRoll=( rand()%6 )+1;

  a=a+diceRoll;

  printf("Dice rolled %d\n",diceRoll);
}
printf("sum of all the numbers: %d\n", a);
 printf("will the next row be higher(h), lower(l) or same(s):");
 gets(choice);
for(i=0;i < 3;i++)
{
  diceRoll=( rand()%6 )+1;

  b=b+diceRoll;

  printf("Dice rolled %d\n",diceRoll);
}

if(b==a)

    printf("u rock\n");
    else
        printf("y dude\n");




return 0;

}

Post a Reply

Replies

Oldest  Newest  Rating
0 Patrick Schwarz · December 12, 2015
/images/forum/upload/2015-12-12/d2e1af0408fbcddb8600c80d61a447ec.png/images/forum/upload/2015-12-12/c4ac420623b42829d892a8aa50a6f65e.png

What about mine? it works but I always do everything kinda sloppy and in a very long way, any critics are welcome xD
0 Linguist Llama · October 24, 2015
What is sizeof choice?
What is sizeof "h", sizeof "l" and sizeof "s"?
Do you see the problem?

You should be able to provide one word answers to my questions. It may be confronting to realise that you're wrong, but it is a necessary part of correcting your understanding. Stop making excuses for your education, and start learning, by providing one word answers to my questions.
0 Manisha Kohli · October 18, 2015
printf("will the next row be higher(h), lower(l) or same(s):");

was used to make sure end user is aware that they have limited options
-1 Manisha Kohli · October 18, 2015
char choice[1]; meant 2 characters only ie if the user gives an input of h it will be "h\0" i.e 2 characters!!!
0 Linguist Llama · October 15, 2015
How many characters can you store in choice?

char choice[1];
printf("%zu\n", sizeof choice);


How many characters are required to store "h", "l" or "s"?

printf("%zu\n", sizeof "h");
printf("%zu\n", sizeof "l");
printf("%zu\n", sizeof "s");


http://i0.kym-cdn.com/photos/images/newsfeed/000/385/280/c64.gif
  • 1

C

107,324 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator