Question

In: Computer Science

Need this in C#. Below is my code for Problem 3 of Assignment 2. Just have...

Need this in C#. Below is my code for Problem 3 of Assignment 2. Just have to add the below requirement of calculating the expected winning probability of VCU.

Revisit the program you developed for Problem 3 of Assignment 2. Now your program must calculate the expected winning probability of VCU through simulation. Run the simulation 10,000 times (i.e., play the games 10,000 times) and count the number of wins by VCU. And then, calculate the winning probability by using the following formula. The expected winning probability = the number of wins by vcu / 10,000

using System;

namespace Assignment2Problem3
{
class Program
{
static void Main(string[] args)
{
int scoreUVA= 0;
int scoreVCU=0;
int winsUVA=0;
int winsVCU=0;
Random ranGen = new Random();

Console.WriteLine("---- NCAA Basketball Game Simulator ----");

Console.WriteLine("Please enter any key to start");

Console.ReadKey();

for (int i = 1; i <= 3; i++)
{
  

scoreVCU= ranGen.Next(75, 105);
scoreUVA= ranGen.Next(65, 115);

if(scoreVCU >= scoreUVA)
{
winsVCU++;
  
  
}
else
{
winsUVA++;
}

Console.WriteLine("Game" + i + " result : VCU(" + winsVCU + ") " + scoreVCU + " - " + scoreUVA + " UVA(" + winsUVA + ")");

if (winsVCU==3|| winsUVA ==3)
{
i = 12;
}
  

}
if(winsVCU == 3)
{
Console.WriteLine("VCU wins!");
}
else
{
Console.WriteLine("UVA wins!");
}
}
}
}

Solutions

Expert Solution

Modified c# code :-

using System;

namespace Assignment2Problem3
{
class Program
{
static void Main(string[] args)
{
int scoreUVA= 0;
int scoreVCU=0;
int winsUVA=0;
int winsVCU=0;
float prob;
Random ranGen = new Random();

Console.WriteLine("---- NCAA Basketball Game Simulator ----");

Console.WriteLine("Please enter any key to start");

Console.ReadKey();

for (int i = 1; i <= 10000; i++) //Run Simulation 10000 times
{

scoreVCU= ranGen.Next(75, 105);
scoreUVA= ranGen.Next(65, 115);

    if(scoreVCU >= scoreUVA)
        {
            winsVCU++;

        }
    else
        {
            winsUVA++;
        }

    Console.WriteLine("Game" + i + " result : VCU(" + winsVCU + ") " + scoreVCU + " - " + scoreUVA + " UVA(" + winsUVA + ")");


}
//correct method for division in C#
prob =(float) winsVCU / 10000;                   // incorrect division in c# (prob= winsVCU / 10000)

Console.WriteLine("\n The expected winning probability of VCU =" + prob); // print winning probability of VCU

}
}
}

Screenshot of output :-


Related Solutions

In Python I have a code: here's my problem, and below it is my code. Below...
In Python I have a code: here's my problem, and below it is my code. Below that is the error I received. Please assist. Complete the swapCaps() function to change all lowercase letters in string to uppercase letters and all uppercase letters to lowercase letters. Anything else remains the same. Examples: swapCaps( 'Hope you are all enjoying October' ) returns 'hOPE YOU ARE ALL ENJOYING oCTOBER' swapCaps( 'i hope my caps lock does not get stuck on' ) returns 'I...
Hi I have a java code for my assignment and I have problem with one of...
Hi I have a java code for my assignment and I have problem with one of my methods(slice).the error is Exception in thread "main" java.lang.StackOverflowError Slice method spec: Method Name: slice Return Type: Tuple (with proper generics) Method Parameters: Start (inclusive) and stop (exclusive) indexes. Both of these parameters are "Integer" types (not "int" types). Like "get" above, indexes may be positive or negative. Indexes may be null. Description: Positive indexes work in the normal way Negative indexes are described...
I have a problem with the code for my project. I need the two clients to...
I have a problem with the code for my project. I need the two clients to be able to receive the messages but the code I have done only the server receives the messages. I need the clients to be able to communicate with each other directly not throught the server. The requirements of this "local chat" program must meet are: 1. The chat is performed between 2 clients and a server. 2. The server will first start up and...
Below is my code, Replace the 2 static_cast codes to a simpler C++ code. I would...
Below is my code, Replace the 2 static_cast codes to a simpler C++ code. I would like to find another way to compile the program without using static_cast in my code. Thank you #include <iostream> #include <iomanip> using namespace std; class Population { private: int population, birth, death; public: Population() { population = 2; birth = 0; death = 0; } Population(int x, int y, int z) { if (x < 2) population = 0; else population = x; if...
I need the c# code for the below assignment. Complete PigLatin program in Windows Forms GUI....
I need the c# code for the below assignment. Complete PigLatin program in Windows Forms GUI. Zip the solution project file and attach to this submission. Do this in the GUI format (Windows Form). Be sure and add a Clear Button to reset for entering another word or words. PigLatinGUI Basic Steps in Creating your Program Create your user interface (GUI). Use different font styles but don’t overdo it, Use colors, and Use graphics (You can find all kinds of...
This is the code I have. My problem is my output includes ", 0" at the...
This is the code I have. My problem is my output includes ", 0" at the end and I want to exclude that. // File: main.cpp /*---------- BEGIN - DO NOT EDIT CODE ----------*/ #include <iostream> #include <fstream> #include <sstream> #include <iomanip> using namespace std; using index_t = int; using num_count_t = int; using isConnected_t = bool; using sum_t = int; const int MAX_SIZE = 100; // Global variable to be used to count the recursive calls. int recursiveCount =...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions are suggested for easier procedure of making function.) void remove_node(struct linked_list* list, int rm_node_value) (the function to make) This function removes a node with specified value. If there is only one node in the list, remove the node and remove the list also since there is nothing left. While removing a node, the node should be perfectly freed. If the type of list is...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions are suggested for easier procedure of making function.) void pop_Stack (struct linked_list* list, int number) //*This is the function to make and below is the explanation that should be written in given code. This function removes some nodes in stack manner; the tail of the list will be removed, repeatedly. The parameter (variable number_of_nodes) means the number of nodes that will be removed. When...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions are suggested for easier procedure of making function.) void pop_Stack (struct linked_list* list, int number) //*This is the function to make and below is the explanation that should be written in given code. This function removes some nodes in stack manner; the tail of the list will be removed, repeatedly. The parameter (variable 'number') means the number of nodes that will be removed. When...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions are suggested for easier procedure of making function.) void remove_list(struct linked_list* list) //*This is the function to make and below is the explanation that should be written in given code. "This function removes the list. When the list is removed, all the memory should be released to operating system (OS) so that OS lets other computer programs use this. While deleting the list, every...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT