# Thread: homework finalising help.....

1. ## homework finalising help.....

I know its not allowed to post homework questions here unless i have most of the code done and i think i have done most of it so here goes me...:

Question:
The following C program
Code:
```#include<stdio.h>
main()
{
int i;
for (i=0; i<10;i++)
printf("%10d \n",1+rand()%6);
}```
will print out 10 random integers.
Therefore, the operation of
Code:
`1+ rand()%6`
in the printf statement can be used to
model the rolling a Six-Sided Die.

Write a complete C program to model the following game of rolling two dice:
A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5
and 6 spots. After the dice have come to rest, the sum of the spots on the two
upward faces is calculated.

(i) If the sum is 7 or 11 on the first throw, the player wins.
(ii) If the sum is 2, 3, or 12 on the first throw, the player loses.
(iii) If the sum is 4, 5, 6, 8, 9 or 10 on the first throw, the sum becomes the
player’s point. To win, you must continue rolling the dice until you
make your point. However, the player loses by rolling a 7 before
making the point.
Sample runs for the game are as follows:
Player rolled 5 + 6 = 11
Player wins
Player rolled 4 + 1 = 5
Point is 5
Player rolled 6 + 2 = 8
Player rolled 1 + 2 = 3
Player rolled 3 + 2 = 5
Player wins
Player rolled 4 + 6 = 10
Point is 10
Player rolled 3 + 4 = 7
Player loses
Player rolled 1 + 1 = 2
Player loses

Code:
Code:
```S.rand(time(NULL))
a= 1 + rand()%6;
b= 1 + rand()%6;
c= a + b

if
c= 7||11
printf("you win")
else
c= 2||3||12
printf("you lose")
else
c= 4||5||6||8||9||10
endif

while{(f!=c)
d= 1 + rand()%6;
e= 1 + rand()%6;
f= d + e
if f= 7||11
printf("you lose")}

printf("you win")```
i know that the code is veeeery wrong and i dont know how to code properly as you see i dont know how to begin or end any help would be apreciated and the wors thing is that the assingment has 5 questions and this is the only one i know how to start so can i possibly post the rest of the questions to get help with them and the assingment is due next tuesday?
Thank you all in advance.

2. What specifically do you need help with first. Pick one thing, once you understand how to do that, move on to the next. So what first don't you know how to do?

There is also a FAQ here in the FAQ section on using random numbers, as well as tutorials on arrays and such that you may want to look at.

Quzah.

3. well the above code is supposedly right as per the tutor but the thing is i dont know how to finalise it (ie make it runable on a sim) and ill take a look at the faqs

4. Yes your tutor has given you the pseudocode for the ALGORITHM that needs to be implemented. It is your job to translate that pseudocode into C code. So where is your effort?

5. actually all the tutor did was look at my code and say thas right and i had a do-while loop in there but he said it was overkill so now will this code do the job?

6. Care to post your own code?
We aren't going to write your assignment for you.

7. alright i know ur not going to write my homework for me and i dont want you to i just want to know how to end a code that looks like that and trust me i did wirte that code! all the tutor did was vhange the commas to || and told me that a do while loop is too much....and if not gonna offer any help please just sayso atleast the guy from the top said some thing useful instead of insulting me.

8. Ok, let me see if I understand this...

THIS is your C code?
Code:
```S.rand(time(NULL))
a= 1 + rand()%6;
b= 1 + rand()%6;
c= a + b

if
c= 7||11
printf("you win")
else
c= 2||3||12
printf("you lose")
else
c= 4||5||6||8||9||10
endif

while{(f!=c)
d= 1 + rand()%6;
e= 1 + rand()%6;
f= d + e
if f= 7||11
printf("you lose")}

printf("you win")```
And your tutor said it was ok?

WOW...

9. It looks more like pseudo-code to me.

It's detailed enough that making it C code shouldn't be too much trouble at all.

10. Originally Posted by Salem
It looks more like pseudo-code to me.

It's detailed enough that making it C code shouldn't be too much trouble at all.
I've read his first message half a dozen times... It's totally unclear where that came from, so I have to assume it's his...

11. thank you guys for your very helpful input and may god bless you all.

12. Originally Posted by Hugeknight
thank you guys for your very helpful input and may god bless you all.
You want our help... either A) clarify if that is your code or B) post the actual code...

How can we help you when we don't know what we're helping you with?

13. you are missing a few libraries
time.h
stdlib.h

and you should put a return 0; statement in there

14. dude i told i sat down wrote a wrong code the tutor came and told that thats ^ the wa to do it and i think i STATED before that o know nothing about c programming so give me a break ok!
and how would i possibly be able to clarify that that code is mine?
and yea there is no actual code.....

15. time4f5 thanks!

Popular pages Recent additions