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

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]...
How can I improve my code below to meet the requirements of this assignment with syntax...
How can I improve my code below to meet the requirements of this assignment with syntax add to my code to complete the assignment below: #include <iostream> #include <vector> using namespace std; class Inventory { private: int itemNumber; int quantity; double cost; double totalCost; public: Inventory() { itemNumber = 0; quantity = 0; cost = 0; totalCost = 0; } Inventory(int n, int q, double c) { itemNumber = n; quantity = q; cost = c; setTotalCost(); } void setItemNumber(int...
So I have written a code for it but i just have a problem with the...
So I have written a code for it but i just have a problem with the output. For the month with the highest temperature and lowest temperature, my code starts at 0 instead of 1. For example if I input that month 1 had a high of 20 and low of -10, and every other month had much warmer weather than that, it should say "The month with the lowest temperature is 1" but instead it says "The month with...
This problem needs to be solved with source code. I need a C++ program that will...
This problem needs to be solved with source code. I need a C++ program that will help me solve this question. I need it in C++, please. Writing with comments so it maybe cleared. 1.2. We received the following ciphertext which was encoded with a shift cipher: xultpaajcxitltlxaarpjhtiwtgxktghidhipxciwtvgtpilpit ghlxiwiwtxgqadds. 1. Perform an attack against the cipher based on a letter frequency count: How many letters do you have to identify through a frequency count to recover the key? What is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT