Thread: Dice roll and count.

  1. #1
    Registered User
    Join Date
    Jul 2014
    Posts
    5

    Dice roll and count.

    Hello. I am pretty new to C and I am in CIS 150. My Lab requires that I write a program to roll a single die 150 times and count how many times each side is rolled. example: 1 rolled 10 times, 2 rolled 25 times,...etc. I have a for loop to roll the die and get the random rolls but I cannot figure out how to count the rolls and then write a code to express it in percentages. Any thoughts would help.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Have you considered an array that has a size of the number of "sides" of your die to hold the "count" for each "side".

    Jim

  3. #3
    Registered User
    Join Date
    Jul 2014
    Posts
    5
    Prof will not let us use code we have not covered in class. He only wants us to use while and for loops to randomize the dice, calculate the number of times each side lands and calculate the percentage.

    http://cboard.cprogramming.com/image...AASUVORK5CYII=

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Then how about separate variables, each representing one side of the die, to count the occurrence of each?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > Prof will not let us use code we have not covered in class.
    And just how do you expect us to know what you have (or haven't) been taught so far, never mind the subset of that which you managed to learn.
    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.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    I suggest writing the code that you do know how to write and are allowed to use.

    I suggest reading the homework policy on this site; we are NOT going to do your homework!!

    Edit: I suggest reading this FAQ
    For, While and Do While Loops in C - Cprogramming.com

    Because, I do NOT think you really know what a for loop does based on your OP.

    Quote Originally Posted by Cody Staus View Post
    I have a for loop to roll the die and get the random rolls but I cannot figure out how to count the rolls and ...
    Tim S.
    Last edited by stahta01; 07-11-2014 at 05:45 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simulating a dice roll, extreme beginner needs help
    By maybetomorrow in forum C Programming
    Replies: 10
    Last Post: 01-25-2014, 06:47 AM
  2. Dice Roll
    By seanksg in forum C Programming
    Replies: 4
    Last Post: 05-13-2011, 12:37 AM
  3. read roll no., marks, count pass and fail
    By jackson6612 in forum C++ Programming
    Replies: 1
    Last Post: 04-23-2011, 11:51 PM
  4. Dice Roll Program
    By HeidiPagel in forum C Programming
    Replies: 7
    Last Post: 12-13-2010, 10:39 AM
  5. C++ dice roll need help
    By catdieselpow in forum C++ Programming
    Replies: 1
    Last Post: 10-07-2007, 01:32 PM