Like Tree4Likes

homework finalising help.....

This is a discussion on homework finalising help..... within the C Programming forums, part of the General Programming Boards category; I know its not allowed to post homework questions here unless i have most of the code done and i ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    11

    Unhappy 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.
    Last edited by Hugeknight; 05-11-2011 at 03:21 AM. Reason: mistake in code

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    11
    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
    Last edited by Hugeknight; 05-11-2011 at 04:16 AM.

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    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?
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  5. #5
    Registered User
    Join Date
    May 2011
    Posts
    11
    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. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Care to post your own code?
    We aren't going to write your assignment for you.

  7. #7
    Registered User
    Join Date
    May 2011
    Posts
    11
    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. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    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...
    ImBack92 likes this.

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,532
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Salem View Post
    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. #11
    Registered User
    Join Date
    May 2011
    Posts
    11
    thank you guys for your very helpful input and may god bless you all.
    ImBack92 likes this.

  12. #12
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Hugeknight View Post
    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...

    Your first message was very unclear about this...
    How can we help you when we don't know what we're helping you with?

  13. #13
    Registered User
    Join Date
    Mar 2011
    Location
    Baltimore Md. USA
    Posts
    58
    you are missing a few libraries
    time.h
    stdlib.h

    and you should put a return 0; statement in there

  14. #14
    Registered User
    Join Date
    May 2011
    Posts
    11
    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. #15
    Registered User
    Join Date
    May 2011
    Posts
    11
    time4f5 thanks!

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework help.
    By PoJo7467 in forum C Programming
    Replies: 7
    Last Post: 11-30-2009, 11:19 AM
  2. Need help on my homework
    By mejv3 in forum C++ Programming
    Replies: 15
    Last Post: 10-11-2005, 03:43 PM
  3. homework help
    By computerjunkie5 in forum C++ Programming
    Replies: 13
    Last Post: 10-27-2003, 10:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21