locked
Coin Loss RRS feed

  • Question

  • Write a program that simulates a coin toss. Generate a random number between 0 and 1. If that value is less than .5, make it heads. Otherwise, output tails.
    please help I don't how to write the code
    Tuesday, January 7, 2014 8:15 PM

Answers

  • It is generally against policy to just give out code, especially if it is for a homework assignment.

    To complete this assignment, you will need do the following:

    1. Create a Console Application in Visual Studio for this problem.  Put your code in the Main method of the Program.cs file.
    2. Use the System.Random class and execute its NextDouble method which returns a random number between 0 and 1.  
    3. Store that value into a variable.
    4. Next, use an If statement to check if the value of the variable is less than 0.5.
    5. If the value of the variable is less than 0.5, then use Console.WriteLine to output "Heads"
    6. If the value of the variable is greater than or equal to 0.5, then use the Console.WriteLine to output "Tails" 

    I hope this will get you started.  Make an attempt to solve the problem and if you get stuck, post here again the specific problem you are having and we can help you with it.


    Tuesday, January 7, 2014 9:15 PM