473,387 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Dice Loop- the number 1 can't be rolled

I can run my dice loop but the only problem is that the number 1 can't be rolled no matter how large the number can roll..

i tried to change then value of x, rrRolls - x
Expand|Select|Wrap|Line Numbers
  1.  
  2.                   arrRolls[rrRolls-1]++;
  3.  
but it gets another number that never rolled.

sorry my English is not that good..
please help me out,, thanks..


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. #include <cstdlib>
  4.  
  5. #include <time.h>
  6.  
  7. #include <iomanip>
  8.  
  9. using namespace std;
  10.  
  11. int main(int argc, char* argv)
  12.  
  13. {
  14.  
  15. int rollDice();
  16.  
  17.  int rrRolls;
  18.  
  19.             int numRolls;
  20.  
  21.             int arrRolls[12];
  22.  
  23.             int dieRoll;
  24.  
  25.             int dice1;
  26.  
  27.             int dice2;
  28.  
  29.             int total_dice;
  30.  
  31.             int dieRoll1;
  32.  
  33.             srand((unsigned)time(0));
  34.  
  35.             cout << "How many times would you like to roll the dice?" << endl;
  36.  
  37.             cin >> numRolls;
  38.  
  39.             cout <<" "<< endl;
  40.  
  41.             for (int k = 0; k <12; k++)
  42.  
  43.             {
  44.  
  45. arrRolls[k] =0;
  46.  
  47.             }
  48.  
  49.             for (int i = 0; i <= numRolls; i++)
  50.  
  51.             {
  52.  
  53.                   dice1 =rand()%6+1;
  54.  
  55.                   dice2 =rand()%6+1;
  56.  
  57. rrRolls = dice1 + dice2;
  58.  
  59.                   dieRoll = rollDice();
  60.  
  61.                   dieRoll1 = rollDice();
  62.  
  63.                   cout << "D1 " << dieRoll1<< setw(10) << "D2: " << dieRoll << setw(10) << "total: " << dieRoll1 + dieRoll << endl;
  64.  
  65.                   arrRolls[rrRolls-1]++;
  66.  
  67.             }
  68.  
  69.             cout <<" "<< endl;
  70.  
  71.             cout << "Dice Rolls Total" << endl;
  72.  
  73.             for(int c =0;c < 12; c++)
  74.  
  75.             {
  76.  
  77.                   cout << c + 1 << " = " << arrRolls[c] << endl;
  78.  
  79.             }
  80.  
  81. return 0;
  82.  
  83. }
  84.  
  85. int rollDice()
  86.  
  87. {
  88.  
  89.       int result;
  90.  
  91.       result = (rand() % 6) + 1;
  92.  
  93.       return result;
  94.  
  95. }
  96.  
Jan 30 '08 #1
1 1552
Ganon11
3,652 Expert 2GB
You are rolling two six sided dice - thus, the sum can be anywhere from 2-12 (1+1 to 6+6). You are not getting a 1 because it is impossible.
Jan 31 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Charles Alexander | last post by:
Hello I am new to php & MySQL - I am trying to retrieve some records from a MySQL table and redisplay them. The data in list form looks like this: Sample_ID Marker_ID Variation ...
1
by: lawentzel | last post by:
I am new to PHP and am an avid RPG gamer. I am looking to use PhpMyChat to be able to game with friends all over the US. With that having been said, PhpMyChat seems to offer a lot of what I am...
32
by: Wenjie | last post by:
Hello, We had a code review with the argument of whether "i" is out of scope as illustrated below: for (int i=0; i<2004; i++) { doSomething(i); }
3
by: Gustavo Randich | last post by:
The following seems to be a bug. The execution returns rows 1,2. It should return 1,1. In fact, if I run the code within a stored procedure alone (not in a trigger), the loop doesn't overwrite the...
5
by: Martin Schou | last post by:
Please ignore the extreme simplicity of the task :-) I'm new to C, which explains why I'm doing an exercise like this. In the following tripple nested loop: int digit1 = 1; int digit2 = 0;...
2
by: Alex | last post by:
Compiler - Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland Linker - Turbo Incremental Link 5.65 Copyright (c) 1997-2002 Borland Platform - Win32 (XP) Quite by accident I stumbled...
101
by: Elijah Cardon | last post by:
Let's say I have m dice having n sides, such that n^m is not going to bust int as a datatype. With m=4 and n=6, an outcome might be {2, 5, 1, 2}. What is a good way to represent this in c so that...
4
by: dpp4669 | last post by:
I need help with writing a program to use randmax and the standard deviation when u roll the dice 10000 times I know you will need the standard dev. and the average where do i put the randmax and do...
17
by: Jose Durazo | last post by:
Hello, I'm doing an exercise to simulate rolling a pair of dice 36,000 times, then count and display how many times the simulation rolls each possible sum. For some reason each time I run my...
38
by: d0ugg | last post by:
I'm writing a program that will have to roll the dice A and dice B one million times, and calculate the percentage of times that the dies will be equal. I'm having trouble to figure out how the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.