DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
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;
    }


Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links