Reply embedded...

> -----Original Message-----
> From: darkshadow_x21 [mailto:[EMAIL PROTECTED]
> Sent: Thursday, February 10, 2005 9:40 AM
> To: [email protected]
> Subject: [C-Paradise] Still need help
> 
> 
> i didn't really understand the help i got from shyan since i am
> barely learning the c++ languange. 

It helps to say which part you don't understand.  May be reading the reply a
few times might help.


> all i need is to know how to
> count and total up thwe values for each number: for instance if a 6
> is rolled it will count 1 for 6 and show me the percentage of
> getting six after about 10 rolls or something. plz help

Is this what you have to do?
- Roll two dice.  Sum the value (2 to 12).
- Record the number of times each sum turn out for a total of 10 rolls.
- ...?

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

As I said in the previous reply, the standard C++ headers are <iostream> and
<cstdlib> respectively.  If your compiler doesn't have them, your compiler
is too old and non-conforming.

   #include <iostream>
   #include <stdlib>
   #include <ctime>  /* for time() function */
   using namespace std;

Your course should cover namespace if your teacher expects you to use the
standard library.  


> void main ()

Should be:
   int main()


> {
> randomize ();

This is not the standard function.  The standard way is:
    srand((unsigned int)time(0));

> unsigned int c,a,b;

> unsigned int total[12];

Don't use magic number and you have to initialize the array to zero.

    const int MAX_DICE_SUM = 13
    unsigned int total[MAX_DICE_SUM] = {0};


> int max=13;
  ^^^^^^^^^^
Remove this.

> for (int i=1;i<=10;i++)

   const int MAX_ROLL = 10;
   for (int i = 0; i < MAX_ROLL; ++i)


>  {
>  a=rand() % 6 + 1;
>  b=rand() % 6 + 1;
>  c=a+b;
>  cout<<"Number rolled = "<<c<<endl;
>  ++total[c];
>  }


What do you want to do next?  Print the count of the recorded sum or
calculate the percentage?

>       for (int j=2;j<=12;j++)
>        {
>        total[max]=0;
>        total[max]=total[c];
>        cout<<j<<" "<<total[max]<<endl;
>        }
> }

To print the result after MAX_ROLL:
    for (int i = 1; i < MAX_DICE_SUM; ++i)
    {
        cout << "Sum " << i 
             << " turn out " << total[i]
             << " times." << endl;
    }

This is what I suggest you to do: Fire up your debugger and step through the
codes one line at a time to see how it works.  

HTH
Shyan





>-----------------------------------------~-~>
CHECK THE ARCHIVE BEFORE POSTING!!!! Archive is available at 
http://www.eScribe.com/software/C-Paradise/

>------------------------------------------_->


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/C-Paradise/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to