Question

In: Computer Science

Using c# rewrite/edit the following program so that it runs the simulation 10,000 times (play the...

Using c# rewrite/edit the following program so that it runs the simulation 10,000 times (play the games 10,000 times) and count the number wins. Then calculate the winning probability by using the formula:

the expected winning probability = the number of wins / 10,000

using System;
class lottery
{
static void Main()
{
int n, random, choice = 1;
Random randnum = new Random();
  
while (choice == 1)
{
  
Console.Write("\nEnter a integer from 1 to 5:");
n = Convert.ToInt32(Console.ReadLine());
while (n < 1 || n > 5)
{
Console.Write("Invalid Input Enter again");
Console.Write("\nEnter a integer from 1 to 5:");
n = Convert.ToInt32(Console.ReadLine());
}
  
random = randnum.Next(1, 6);

if (n == random)
{
Console.WriteLine("You Won $5.");
}
else
{
Console.WriteLine("You lost $1");
}
Console.Write("1.To continue\n2.To exit\nEnter your choice:");
  
choice = Convert.ToInt32(Console.ReadLine());
  
}
}
}

Solutions

Expert Solution

Please find the updated code and the output below.

using System;
class lottery
{
static void Main()
{
int n, random, count= 1 , number_of_win=0;
Random randnum = new Random();
  
while (count <= 10000)
{
  
random = randnum.Next(1, 6);
n = randnum.Next(1, 6);

if (n == random)
{
number_of_win++;
}
count ++;
}
Console.WriteLine("Number of win is = " + number_of_win);
Console.WriteLine("The expected winning probability is = "+ (number_of_win/10000.0));
}
}


Related Solutions

using C++. edit this code down below so that it will implement stack with linked list...
using C++. edit this code down below so that it will implement stack with linked list contains a default constructor, a copy constructor, and a destructor. #include <iostream> #include <vector> #include <string> #include <stack> #include <limits> using namespace std; class Stack { public: bool isEmpty(); int top(); int pop(); void push(int); void printList(); private: vector<int> elements; }; bool Stack::isEmpty() { return elements.empty(); } int Stack::top() { if(isEmpty()) { throw runtime_error("error: stack is empty"); } return elements.back(); } int Stack::pop() {...
Edit the given program to produce the following output in c++ mode: - Take in the...
Edit the given program to produce the following output in c++ mode: - Take in the name of a superhero & tell him how many villains he/she has to defeat today - The number of villains is randomly generated and should be a number between 11 and 42. - Use a seed of 7. Hint: Compile the program first before making edits What is your name? Hello Captain America There are 42 villains you need to defeat today Oops! one...
Rewrite your most recent high scores program in C++ so that each name/score pair is stored...
Rewrite your most recent high scores program in C++ so that each name/score pair is stored in a struct named Highscore. Except as noted below, this new program will continue to meet all of the requirements of your most recent high scores program. Your new program should meet the following additional requirements: The Highscore struct should have two fields: an int named score and a char array named name. The char array should have 24 elements, making the maximum length...
Rewrite Program to store the pairs of states and capitals so that the questions are displayed...
Rewrite Program to store the pairs of states and capitals so that the questions are displayed randomly. import java.util.*; public class quiz { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String arr[][]= {{"Alabama","Montgomery"},{"Alaska","Juneau"},{"Arizona","Phoenix"}}; int n =arr.length; int count=0; for(int i=0;i<n;i++) { System.out.printf("What is the capital of %s? ",arr[i][0]); String capital=sc.next(); if (arr[i][1].equalsIgnoreCase(capital)) { count++; System.out.println("Your answer is correct"); } else { System.out.printf("The correct answer should be %s\n",arr[i][1]); } } System.out.printf("The correct count is %d",count); } }
Question: Write a complete C++ program that runs multiple tests and calculations using switch statement. Based...
Question: Write a complete C++ program that runs multiple tests and calculations using switch statement. Based on your input and the selection from the keyboard, the program does the followings. If the selection is 1, the program should test the input if it’s positive, negative or zero. For example, the output should be “The selection is 1 to test the input value if it’s positive, negative or equal to zero. The input value 7 is positive” If the selection is...
I am using C++ Write a program that allows two players to play a game of...
I am using C++ Write a program that allows two players to play a game of tic-tac-toe. Use a two-dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that does the following: Displays the contents of the board array. Allows player 1 to select a location on the board for an X. The program should ask the user...
The League with DMA Rewrite your League program from Assignment 8 so that it uses Dynamic...
The League with DMA Rewrite your League program from Assignment 8 so that it uses Dynamic Memory Allocation (DMA) to create the team names and scores arrays. This is a good test of the modularity of your program. You will only need to make slight modifications to your main() function if you wrote your original program using functions similar to the following: void initializeData(string names[], int wins[], int size) void sort(string names[], int wins[], int size) void display(string names[], int...
REWRITE FOLLOWING CODES USING DO...WHILE LOOP. BY USING C LANGUAGE #include <stdio.h> int main(void) {     ...
REWRITE FOLLOWING CODES USING DO...WHILE LOOP. BY USING C LANGUAGE #include <stdio.h> int main(void) {      int count =2; // COUNT TAKEN 2 AS TO PRINT 2 TIMES           while(count--){                printf("\--------------------------------------------\ \n"); printf("\          BBBBB               A                   \ \n"); printf("\          B    B             A A                  \ \n"); printf("\          BBBB              A   A                 \ \n"); printf("\          B    B           AAAAAAA                \ \n"); printf("\          BBBBB           A       A               \ \n"); printf("\---------------------------------------------\ \n");             }                                 return 0; }
Complete the following program so that C = A*B where A and B are the matrices...
Complete the following program so that C = A*B where A and B are the matrices defined below. N=4; M=3; A=rand(M,N); B=rand(N,M); C = ? for m = 1: M    for n = 1 : ? for p = 1 : ? C (m,n) = ?       end    end end You may upload a script
C programming Rewrite the following function using no loops, and only tail call recursion double question5...
C programming Rewrite the following function using no loops, and only tail call recursion double question5 (int in) { int i; int result; for (result = rand(), i = 0; i < in; i += 3) { result /= i; result += rand(); } return result; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT