coins


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: coins

  1. #1
    victor Guest

    coins


    how to simulating a coins that turn and randomly show either heads or tails
    ????????????



  2. #2
    Tim Guest

    Re: coins


    "victor" <victor_cvy@hotmail.com> wrote:
    >
    >how to simulating a coins that turn and randomly show either heads or tails
    >????????????
    >
    >This is something I did that simulates coin tossing:


    int flip(void);

    int main()
    {
    int frequency 0 = 0;
    int frequency 1 = 0;
    int face;
    int counter;

    srand(time(0));

    for (counter = 1; counter <= 20; ++counter)
    {
    face = flip();

    switch(face)
    {
    case 0:
    ++frequency0;
    break;
    case 1:
    ++frequency1;
    break;
    default:
    cout << "Don't read this!";
    }
    }

    cout << "Tails were rolled " << frequency0 << " times";
    cout << "Heads were rolled " << frequency1 << " times";

    return 0;
    }

    int flip(void)
    {
    int face;
    face = rand() % 2;
    return face;
    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center