Generation

generate functionSat, 26 Nov 2022

the user also specifies the number of coin tosses at the beginning of the program. tosses a coin and then determines that did it fall on the side of the head or the writing. After the coin is tossed, write the result on the screen, that is, how many times there were heads and how many times there were writing.

// User enters the number of coin tosses int numberOfTosses = int.Parse(Console.ReadLine()); // random generator of numbers Random random = new Random(); // variables for counting int headsCount = 0; int tailsCount = 0; // loop for the number of coin tosses for (int i = 0; i < numberOfTosses; i++) { // random generation of numbers int toss = random.Next(0, 2); // increase the number of heads if (toss == 0) { headsCount++; } // increase the number of tails else { tailsCount++; } } Console.WriteLine("Number of heads: " + headsCount); Console.WriteLine("Number of tails: " + tailsCount);

Questions about programming?Chat with your personal AI assistant