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...
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...
C++ Simple Programming Assignment you need to build off of the code below: #include using namespace...
C++ Simple Programming Assignment you need to build off of the code below: #include using namespace std; // class definition class Fraction {         // two data members         // one representing numerator         int numerator;         // other, representing denominator         int denominator;         public:                 void set (int numerator, int denominator);                 Fraction addedTo (Fraction f);                 Fraction subtract (Fraction f);                 Fraction multipliedBy (Fraction f);                 Fraction dividedBy (Fraction f);                 bool isEqualTo (Fraction f);                 void print (); }; void Fraction :: set (int numerator, int denominator) {         this...
Directions: Convert the following problems below to c++ equivalent code Problem 3: Take any 2 digit...
Directions: Convert the following problems below to c++ equivalent code Problem 3: Take any 2 digit number from 31 to 99. (You do not have to check the numbers just assume the user will enter a valid number so long as you tell them to). Store an extra copy of this number for later 3.   Add 82 to the number. 4.    Remove the hundreds place from your number 5.    Add 1 to the number. 6.    Subtract this from your...
Validating Input file, So for my C++ assignment, my professor says we need to validate the...
Validating Input file, So for my C++ assignment, my professor says we need to validate the Input File, Which means, if the line is missing a comma, one of the 3 information, or the string is a white line, it will ignore it. If the line has a white line, the program will correct it and will read in the line. I will store these into an Array, and display them in First name, Last name, and Number of Votes...
I need assistance translating a custom C++ program to MIPS. My C++ code is the following:...
I need assistance translating a custom C++ program to MIPS. My C++ code is the following: I have made numerous attempts on my own to no avail, any assistance is appreciated. Also, template code for this solution is provided below: #include int moveRobots(int *, int *, int, int ); int getNew(int, int); int main() { int x[4], y[4], i, j, myX = 25, myY = 25, move, status = 1; // initialize positions of four robots x[0] = 0; y[0]...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT