In: Computer Science
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!");
}
}
}
}
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 :-