Thread: Rolling Dice Program

  1. #1
    Registered User
    Join Date
    Jul 2016
    Posts
    1

    Rolling Dice Program

    Rolling Dice Program-screenshot-175-png

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,082
    Write it and find out!
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Banned
    Join Date
    Oct 2014
    Location
    Home
    Posts
    135
    Code:
    #include <math.h>#include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <conio.h>
    
    
    unsigned long playerone()
    {
    int dice, risk1 = 0;
    unsigned long score;
    char keypress;
    
    
    keypress = '';
    
    
    score = 0;
    
    
    turn1:;
    srand(time(NULL));
    dice = 1+(rand()%6);
    
    
    printf("\n player1 dice = %d", dice);
    
    
    if(dice == 1)
    {
    score = 0;
    goto exitturn1;
    }
    
    
    score = score + (unsigned long)dice;
    
    
    printf("\n Would you like to risk it? (-1 for no)");
    scanf("%d", &risk1);
    if(risk1 == -1)
    {
    goto exitturn1;
    }
    goto turn1;
    
    
    exitturn1:;
    
    
    printf("\n player1 score = %lu", score);
    return(score);
    }
    
    
    unsigned long playertwo()
    {
    int dice, risk2 = 0;
    unsigned long score;
    char keypress;
    
    
    keypress = '';
    
    
    score = 0;
    
    
    turn2:;
    srand(time(NULL));
    dice = 1+(rand()%6);
    
    
    printf("\n player2 dice = %d", dice);
    
    
    if(dice == 1)
    {
    score = 0;
    goto exitturn2;
    }
    
    
    score = score + (unsigned long)dice;
    
    
    printf("\n Would you like to risk it? (-1 for no)");
    scanf("%d", &risk2);
    if(risk2 == -1)
    {
    goto exitturn2;
    }
    goto turn2;
    
    
    exitturn2:;
    
    
    printf("\n player2 score = %lu", score);
    return(score);
    }
    
    
    int main()
    {
    unsigned long tally1, tally2, sum1, sum2;
    
    
    sum1 = 0;
    sum2 = 0;
    
    
    start:;
    printf("\n\n\n");
    
    
    tally1 = playerone();
    sum1 = sum1 + tally1;
    printf("\n player1 tally: %lu", sum1);
    if(sum1 >= 100)
    {
    printf("\n  player one wins");
    goto exitprg;
    }
    
    
    printf("\n");
    tally2 = playertwo();
    sum2 = sum2 + tally2;
    printf("\n  player2 tally: %lu", sum2);
    if(sum2 >= 100)
    {
    printf("\n player two wins");
    goto exitprg;
    }
    
    
    printf("\n\n\n\n\n Please press a key to continue.  Thank you!");
    getch();
    goto start;
    
    
    exitprg:;
    return(0);
    }

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,608
    laserlight is right however these programs are very hard and uses a lot of functions
    Yeah it's almost like why bother trying and getting used to solving problems.

    I hope the OP takes the opportunity to write something better, 'cause chances are it will be. OP might know how to use a loop.

  5. #5
    Banned
    Join Date
    Oct 2014
    Location
    Home
    Posts
    135
    Quote Originally Posted by whiteflags View Post
    Yeah it's almost like why bother trying and getting used to solving problems.

    I hope the OP takes the opportunity to write something better, 'cause chances are it will be. OP might know how to use a loop.
    Jesus Christ! Bless GOD, Jesus Christ, The Holy Spirit, and Mary# Then bless my real mom Huong Thi Thuyen Vu. Honours to my real mom Huong Thi Thuyen Vu. Honours to my real dad Nguyen Binh Thuy. Congratulations to my real two sisters Nguyen Khoa Thuyen and Nguyen Khoa Thi. whiteflags: you are right. If you try to be better you will be better, but GOD gives each person a gift. I'm only five foot five inches tall. So I don't have the gift to be a basketball dunker. So the trick is knowing where your talent is and going with it. If you are more left brain then you are more logical and prefer reality. If you are right brain you are more intuitive and know things more like 'I feel this is right' and it ends up being right. I've been trained with BASIC from 9 years old so gotos statements are a part of me now. Thank you Jesus Christ. P.S. If you notice your numbers to English is extremely efficient compared to mine. Amen.

  6. #6
    Registered User
    Join Date
    Sep 2014
    Posts
    364
    Quote Originally Posted by Tien Nguyen View Post
    I've been trained with BASIC from 9 years old so gotos statements are a part of me now.
    If have also started with BASIC in the 1980's (on TI-99/A4 and Commodore 64). But a few years later (1990's) my BASIC-programs havn't 'goto' anymore.
    BASIC have also 'if' and 'for' to control a program. Functions can be build in BASIC with 'gosub', 'on # gosub' and 'return'.
    So, please don't recommend 'goto'!

    Also, please don't recommend to include 'conio.h'! It is deprecated and outdated!
    Last edited by WoodSTokk; 07-03-2016 at 02:26 PM.
    Other have classes, we are class

  7. #7
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,608
    whiteflags: you are right.
    Good.
    If you try to be better you will be better, but GOD gives each person a gift.
    Even so I want to make this request now: next time you want to try someone's homework, could you write it, and start a new thread, so that we can talk about your code?

    I will get to the reasons why, but I need to respond to the excuses you gave for behavior.

    I'm only five foot five inches tall. So I don't have the gift to be a basketball dunker.
    I wish you would give us the same respect you give basketball players and stay off our court.

    So the trick is knowing where your talent is and going with it. If you are more left brain then you are more logical and prefer reality. If you are right brain you are more intuitive and know things more like 'I feel this is right' and it ends up being right.
    Well, it's a bad way to program, the computer doesn't care about how you feel.

    I've been trained with BASIC from 9 years old so gotos statements are a part of me now.
    Hey! You said something that actually makes some sense.

    Well, I don't know about your experience. You've lied about it before in other places so the reality of the situation will be forever muddy. But the thing is, learning to program C or C++ by making it look like BASIC is not doing anyone, even yourself, a favor. What I don't want to happen is someone comes along with a problem that is just easy enough for you to solve, and you post your C++/BASIC mixture from hell. Then, depending on their own experience, they might think that is what someone normal with a working knowledge does.

    I certainly hope you agree with me that you don't have a working knowledge. You don't know how to write a program that someone would actually want to read. But again, you just post code! No explanation, no context, just your attempt.

    If you want to do that, fine, but I think you deserve your own thread, where we can talk to and about you specifically without introducing your bad habits to anyone else. They have their own issues with the problems that they post. They deserve the right to solve it their own way, not your way. Because when you post the answer to a problem, it mostly ruins the fun. People who deserve to see other solutions usually put in substantial effort first. For example, they might post a short, self contained, compileable example which gets fixed. Then, someone comes along with separate but functional improvements or ideas.

    Right now you can't really help everyone. C/C++ is not BASIC. No one should see that.

  8. #8
    Banned
    Join Date
    Oct 2014
    Location
    Home
    Posts
    135
    Quote Originally Posted by whiteflags View Post
    Good.

    Even so I want to make this request now: next time you want to try someone's homework, could you write it, and start a new thread, so that we can talk about your code?

    I will get to the reasons why, but I need to respond to the excuses you gave for behavior.


    I wish you would give us the same respect you give basketball players and stay off our court.


    Well, it's a bad way to program, the computer doesn't care about how you feel.


    Hey! You said something that actually makes some sense.

    Well, I don't know about your experience. You've lied about it before in other places so the reality of the situation will be forever muddy. But the thing is, learning to program C or C++ by making it look like BASIC is not doing anyone, even yourself, a favor. What I don't want to happen is someone comes along with a problem that is just easy enough for you to solve, and you post your C++/BASIC mixture from hell. Then, depending on their own experience, they might think that is what someone normal with a working knowledge does.

    I certainly hope you agree with me that you don't have a working knowledge. You don't know how to write a program that someone would actually want to read. But again, you just post code! No explanation, no context, just your attempt.

    If you want to do that, fine, but I think you deserve your own thread, where we can talk to and about you specifically without introducing your bad habits to anyone else. They have their own issues with the problems that they post. They deserve the right to solve it their own way, not your way. Because when you post the answer to a problem, it mostly ruins the fun. People who deserve to see other solutions usually put in substantial effort first. For example, they might post a short, self contained, compileable example which gets fixed. Then, someone comes along with separate but functional improvements or ideas.

    Right now you can't really help everyone. C/C++ is not BASIC. No one should see that.
    You are certainly right about some things? I write program that works. I expect that a real world situation is where a program just works! If you nitpick you may never get the job done on time and on schedule. We are talking about C. Although it veries to some extent from one C to another C it is still C. What I agree with to some extent is the homework part. I believe a person should and MUST do their own work. However if there is a problem then when the person posts THEIR work others can give suggestions on what may be the solution to a bottleneck. Sometimes people need a jump start. They are so lost because it is their very first time that they mess it all up and give up even for life. The idea of a school is to graduate and eventually get them a job. Not all schools are able to hold a perfect 100% success rate of doing that. The idea of a school is to train an individual to integrate into society with their chosen expertise.

  9. #9
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,608
    I expect that a real world situation is where a program just works! If you nitpick you may never get the job done on time and on schedule.
    It may work but it wouldn't pass a code review; after all it looks more like a really ancient BASIC program than a C program.

  10. #10
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Quote Originally Posted by Tien Nguyen View Post
    Jesus Christ! Bless GOD, Jesus Christ, The Holy Spirit, and Mary# Then bless my real mom Huong Thi Thuyen Vu. Honours to my real mom Huong Thi Thuyen Vu. Honours to my real dad Nguyen Binh Thuy. Congratulations to my real two sisters Nguyen Khoa Thuyen and Nguyen Khoa Thi. laserlight is right however these programs are very hard and uses a lot of functions. Thank you Jesus Christ.
    Hail Satan!

    Official Church of Satan Website | churchofsatan.com

    Edit: the purpose of homework is for people to learn, so don't do their homework for them.

  11. #11
    Registered User
    Join Date
    Sep 2014
    Posts
    364
    Quote Originally Posted by Tien Nguyen View Post
    I write program that works.
    No!

    As example, start your program based on code from your post #3 and when the program ask 'Would you like to risk it?', type x and hit enter.
    Other have classes, we are class

  12. #12
    Banned
    Join Date
    Oct 2014
    Location
    Home
    Posts
    135
    Quote Originally Posted by whiteflags View Post
    Good.

    Even so I want to make this request now: next time you want to try someone's homework, could you write it, and start a new thread, so that we can talk about your code?

    I will get to the reasons why, but I need to respond to the excuses you gave for behavior.


    I wish you would give us the same respect you give basketball players and stay off our court.


    Well, it's a bad way to program, the computer doesn't care about how you feel.


    Hey! You said something that actually makes some sense.

    Well, I don't know about your experience. You've lied about it before in other places so the reality of the situation will be forever muddy. But the thing is, learning to program C or C++ by making it look like BASIC is not doing anyone, even yourself, a favor. What I don't want to happen is someone comes along with a problem that is just easy enough for you to solve, and you post your C++/BASIC mixture from hell. Then, depending on their own experience, they might think that is what someone normal with a working knowledge does.

    I certainly hope you agree with me that you don't have a working knowledge. You don't know how to write a program that someone would actually want to read. But again, you just post code! No explanation, no context, just your attempt.

    If you want to do that, fine, but I think you deserve your own thread, where we can talk to and about you specifically without introducing your bad habits to anyone else. They have their own issues with the problems that they post. They deserve the right to solve it their own way, not your way. Because when you post the answer to a problem, it mostly ruins the fun. People who deserve to see other solutions usually put in substantial effort first. For example, they might post a short, self contained, compileable example which gets fixed. Then, someone comes along with separate but functional improvements or ideas.

    Right now you can't really help everyone. C/C++ is not BASIC. No one should see that.
    You accuse me of lying about my experiences before. I have NEVER once lied about my experiences. I went to Lehigh Carbon Community Colllege in the state of Pennsylvania from 1990 to approximately 1996 with a gap in 1994 and another year to transfer credits to other University/colleges. My father always wanted me to graduate from Lafayette College because it is a good engineering school. I got in for a summer semester however I didn't want to continue so I went to California and messed around a bit. When I was just a kid my dad bought me a computer that I programmed on at 8/9 years old. I've had computers throughout my life since then. All in all I have probably an equivalency of a 2-year Liberal Arts Associates Degree. In fact officially I am missing one course credit from getting my official Associates Two Year Degree. The policy may have changed where I have to retake courses to refresh my mind. I don't want to brag however I feel strong confidence I am able to do a humble amount of things. I've taken official courses in college of Pascal, COBOL, FORTRAN, SQL, ... that's off the top of my head. When I was 9 I learned BASIC for the Commodore 64 computer. In 2014 I learned Borland Turbo C 2.01 and Borland Turbo Assembler 4.1. I've specialized in both especially assembly for the last two years. Now I like you but I've got a girlfriend. Anyways, I just wanted to get the facts straight. No hard feelings. I don't mean to put you down but you should stop going with the crowd. You have a lot of talent and I appreciate that intelligence.

  13. #13
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Quote Originally Posted by Tien Nguyen View Post
    Now I like you but I've got a girlfriend.
    hahahaha

  14. #14
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,687
    OMG such an over-reaction to critic of poorly written code.

    White Flags is fully justified to give responses of what is written, and of course
    you can fully agree or dis-agree with it as free will dictates. However, there is
    being in dis-agreement and there is going overboard.

    C is a functional procedural language and should be used in this way of course.
    There are no strict rules saying you must write code like this or that, but using
    goto labels confuse the program and logic of the code. A goto label in C anyway,
    should only be used in extreme situations, such as exiting from a deeply nested loop
    or routine where using a simple break statement would not logically work.

    I am not saying what you wrote is invalid, I am just trying to explain why other users
    are justified in the practice of the goto statement.
    Double Helix STL

  15. #15
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Remember bumping into this article a while back, relevant to the goto discussion: Using Goto in Linux Kernel Code | Koblents.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rolling a two dice
    By amirul m nasir in forum C Programming
    Replies: 4
    Last Post: 09-10-2011, 05:59 PM
  2. dice rolling in c
    By ceddsoboss in forum C Programming
    Replies: 3
    Last Post: 11-06-2010, 02:44 PM
  3. Replies: 9
    Last Post: 11-11-2007, 02:31 PM
  4. Dice Rolling Program help
    By courtesan in forum C Programming
    Replies: 3
    Last Post: 08-17-2005, 03:14 PM
  5. rolling dice program
    By sunny2005 in forum C Programming
    Replies: 20
    Last Post: 03-21-2005, 04:45 PM

Tags for this Thread