473,216 Members | 1,938 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,216 software developers and data experts.

Counting

A little background regarding what I am doing:
I am supposed to write a small program that simulates rolling dice. I
randomly generated the number like I am supposed to, but then I am
supposed to count the number of times each number occurs(this is my
problem). I am also supposed to print in column for the number, the
max count, the min count, and the average count!!!

Could some one help me!!!

Here is the Code I have so far (I cannot use arrays on this project):

#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

void dice (int & x, int count);

int main ()
{
int count=0;
int x;
dice(x,count);
}
//-------------------------------
void dice (int & x,int count)
{
do
{
srand((unsigned)time(NULL));
x= (rand () %6+1);
cout<< x;
count++;
}
while (count<0);
{
cout<< x;
}
}
-------------------------------------------------------------------------------
Jul 19 '05 #1
4 2285
shell writes:
A little background regarding what I am doing:
I am supposed to write a small program that simulates rolling dice. I
randomly generated the number like I am supposed to, but then I am
supposed to count the number of times each number occurs(this is my
problem). I am also supposed to print in column for the number, the
max count, the min count, and the average count!!!

Could some one help me!!!

Here is the Code I have so far (I cannot use arrays on this project):


I can't think of any sensible way to do this without arrays. (Assuming that
includes array-like things, such as vectors). Perhaps this is an exercise
to build up a lust in your soul for arrays?
Jul 19 '05 #2
Hi,

#include <map>
using namespace std;

// init stuff
map<int> Count;
for( int Cnt = 0; Cnt < 6; ++Cnt ) map[ Cnt ] = 0;

// And use it
++Count[ Dice ];

// And print when ready
for( map<int>::const_iterator Walker = Count.begin(); Walker != Count.end();
++Walker )
{
count << "Number " << Walker->first << " rolled " << Walker->second << "
Times " << endl;
}

// Todo max min etc.

Regards, Ron AF Greve.
"shell" <eu*****@houston.rr.com> wrote in message
news:e7**************************@posting.google.c om...
A little background regarding what I am doing:
I am supposed to write a small program that simulates rolling dice. I
randomly generated the number like I am supposed to, but then I am
supposed to count the number of times each number occurs(this is my
problem). I am also supposed to print in column for the number, the
max count, the min count, and the average count!!!

Could some one help me!!!

Here is the Code I have so far (I cannot use arrays on this project):

#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

void dice (int & x, int count);

int main ()
{
int count=0;
int x;
dice(x,count);
}
//-------------------------------
void dice (int & x,int count)
{
do
{
srand((unsigned)time(NULL));
x= (rand () %6+1);
cout<< x;
count++;
}
while (count<0);
{
cout<< x;
}
}
--------------------------------------------------------------------------

-----
Jul 19 '05 #3
One solution might be to declare 12 integer variables and increment the
appropriate variable via switch statement for each occurance of 'x':

int fisrt=0;, second=0, third=0, fourth=0 ... twelfth=0;

switch (x)
{
case 1: first++;
break;
case 2: second++;
break;
case 3: third++;
. . .

. . .
case 12: twelfth++;
break;
};

After processing each occurance of 'x' you'll have values stored for the
occurances of each number, min values, max values. The rest is a synch!

Jul 19 '05 #4


shell wrote:

A little background regarding what I am doing:
I am supposed to write a small program that simulates rolling dice. I
randomly generated the number like I am supposed to, but then I am
supposed to count the number of times each number occurs(this is my
problem). I am also supposed to print in column for the number, the
max count, the min count, and the average count!!!

Could some one help me!!!

Here is the Code I have so far (I cannot use arrays on this project):
If you cannot use arrays (or any other container), I guess you need to do:

int NrOfOne = 0;
int NrOfTwo = 0;
int NrOfThree = 0;
...

if( x == 1 )
NrOfOne++;

else if( x == 2 )
NrOfTwo++;

...


#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

void dice (int & x, int count);

int main ()
{
int count=0;
int x;
dice(x,count);
}
//-------------------------------
void dice (int & x,int count)
{
do
{
srand((unsigned)time(NULL));
call srand only *once* at the beginning of your program!

x= (rand () %6+1);
cout<< x;
count++;
}
while (count<0);
{
cout<< x;
}
}

-------------------------------------------------------------------------------


--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Elbert Lev | last post by:
Please correct me if I'm wrong. Python (as I understand) uses reference counting to determine when to delete the object. As soon as the object goes out of the scope it is deleted. Python does...
1
by: ash | last post by:
hi does anyone has any experience with flyweight pattern with refernce counting i want to share objects between multiple clients and want to delete the object from shared pool when the last...
1
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that I don't understand completely. It says "A garbarage...
1
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that I don't understand completely. It says "A garbarage...
18
by: ChadDiesel | last post by:
I appreciate the help on this group. I know I've posted a lot here the last couple of weeks, but I was thrown into a database project at my work with very little Access experience. No other...
7
by: zets | last post by:
I need a macro for counting the bits in the odd positions of a given input (of any type, char, pointer, int, struct, whatever). Is there any clever way I could not think of, to do it efficiently? ...
1
by: j | last post by:
Hi, I've been trying to do line/character counts on documents that are being uploaded. As well as the "counting" I also have to remove certain sections from the file. So, firstly I was working...
4
by: aaronfude | last post by:
Hi, Please consider the following class (it's not really my class, but it's a good example for my question): class Vector { int myN; double *myX; Vector(int n) : myN(n), myX(new double) { }...
1
by: oec.deepak | last post by:
Hi Cn any one telll me what is Reference counting in C++.
3
by: nitric | last post by:
hey guys, i'm really stuck on this program. It's basically a survey and I have to ask people what drinks they like. 1-4, coffee tea oj and lemonade. i'm having trouble counting the TOTAL NUMBER...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.