Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Problem with while loops in C

  1. Sep 5, 2008 #1
    1. The problem statement, all variables and given/known data

    Write a program that will roll a pair of six-sided dice (int variables named redDie and blueDie) and will give you 5 points every time you roll doubles (pair of 2s, 3s, 4s, and 5s) and 10 points if you roll snake-eyes (pair of 1s) or boxcars (pair of 6s). Run your program 10 times and see how many points you make. NOTE: This lab presents an interesting coding problem and emphasizes that gambling is for people who can’t do the math!!

    2. Relevant equations

    This was given to us for help at the beginning of the equation

    3. The attempt at a solution

    Here's what I got. The program runs just fine without the when loop, but with the loop in place, it takes the output of the first roll and copies that output 10 times, instead of executing a new roll at the beginning of each loop.

    Any help that you could give me would be really helpful.

  2. jcsd
  3. Sep 5, 2008 #2
    the %6 part means "remainder after division by 6". For instance, "9 % 5" is 4 since 4 is the remainder when you divide 9 by 5.

    I have no more answers for you, but I do have a question of my own. Why is it that you have capitalized the second word in redDie and blueDie, but not in dierolls? Do you think it is a good use of your scarcest resource to spend it on deciding case by case what standard to apply when naming things?
  4. Sep 5, 2008 #3
    I have no idea why they are capitalized...they were the variables given by the department. Maybe it would make it better for grading purposes? Thanks for your answer to the first part!
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook