Chalange #2

+4 Thalinda Bandara · August 11, 2015


int diceroll1,diceroll2,diceroll3,sum=0,sum1;
int rolls;
char high;



printf("Pleace Enter you input with simpl letters/n");


        printf("Good Gues it's high value");
else if(high=='l'&&sum

Post a Reply


- page 1
Oldest  Newest  Rating
0 c student · August 19, 2015
in c, any sequence of characters which ends with a null terminator can be considered as a string be it one or thirty characters long.  double quotes represents a string with an implied null terminator at the end like so:
"this is a string"    // == this is a string\0

here is the man page for scanf:

if you called rand, you will need to seed it with srand to alter the calculated value.  if you use a static seed, your rand will output a static value, if your seed is dynamic, your rand will output dynamic values.  the most common seed is the following:


srand (time (NULL));

you will only be required to call it once
0 Toyen . · August 26, 2015
I see, thanks for the link, but what can I do with it and how can I use the srand function in my program?

And why did Bucky and Thalinda did not need to use it?
0 Toyen . · August 14, 2015
Congrats! I am trying to complete this challenge myself but no luck so far.

I am trying to print the first roll but its not working.

Here it is:


Basically, until the user enters r to roll the dice, I will keep asking him to roll it. Thats what I was trying to do here.

And if he enters r, the dice rolls for the first time.
0 Thalinda Bandara · August 14, 2015
hi frend thanks for commenting.  in your programm there are some missing semicolans and i think there more actualy i can't see you code like this so if you can pleace upload as i upload. and i can't understand why are you using do while loop in there. k i have created the program using your logic k see is it doing what you wanted
0 Thalinda Bandara · August 14, 2015
you can look new programm in here use this site to upload
0 Toyen . · August 14, 2015
Hey there again :)

The first part of the program I posted earlier now works but not properly.

The idea behind the do function was that if the user does not press "r", then keep asking the user to press "r".

Once they press r, then the dice rolls for the first time.


even when I press "r", it keeps looping asking me to press r.

What did I do wrong?

In the while statement I specified that while roll does not equal r, then keep looping the do statement.

Once roll is equal to "r", it should stop looping and roll the dice but this doesnt happen.
0 c student · August 15, 2015
you cannot compare an array with a string like that.  you have three choices in this situation

1. make roll of type char:
char roll;

scanf ("%c", &roll);

which will now allow you to compare roll and a character with the comparison operator

while (roll != 'r');

2. compare only the first element of the array with the character.  this also allows the use of the comparison operator

while (roll[0] != 'r');

3. use the strcmp function to compare strings

while (strncmp (roll, "r", 1) != 0);
0 Toyen . · August 15, 2015
Hey there and thanks for your response!

I changed the roll to %c  in the scan function and compared the first element of the array to r but it still doesnt work.

It keeps looping and never prints the dice roll even when I enter r.

Instead it asks me twice to roll the dice again.

I also do not know the strncmp function yet so I looked it up but I dont really get what your intention was, why to use it here to compare only 1 character?

Anyways, here is what my program looks like now:

0 c student · August 16, 2015
you're comparing a character with a string.  it should be
while (roll[0] != 'r')    // single quotes
0 Toyen . · August 16, 2015
Thank you very much!

Why are the single quotations used here though? Is it because I am trying to access a certain element of an array?

Also the program still does not work properly, it asks me twice to press r if I do not press r the first time not just once as intended and the roll it prints is always equal to 144, is there anything wrong with my dice roll ints?
  • 1
  • 2



One of the most popular languages of all time.

Bucky Roberts Administrator