Okay so I'm trying to make a simple console program that calculates the chance of drawing a specific card from a deck of trading cards. At the moment my code looks something like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static string cardOrHand = "null";
static int cardsInDeck = 40;
static void Main(string[] args)
{
Console.WriteLine("Would you like to calculate card or hand probabilities? (card or hand)");
cardOrHand = (Console.ReadLine());
Console.Clear();
if (cardOrHand == "card")
{
cardProbFunction();
}
}
static void cardProbFunction()
{
Fraction frac = new Fraction();
string cardsInDeckInput = "40";
string quantCardInQuestionInput = "0";
string turnToDrawInput = "1";
int turnToDraw = 1;
int quantCardInQuestion = 0;
int drawProbability = 0;
Console.WriteLine("How many cards are in the deck in question?");
cardsInDeckInput = (Console.ReadLine());
cardsInDeck = Int32.Parse(cardsInDeckInput);
Console.Clear();
Console.WriteLine("How many copies of the card in question?");
quantCardInQuestionInput = (Console.ReadLine());
Console.Clear();
quantCardInQuestion = Int32.Parse(quantCardInQuestionInput);
Console.WriteLine("On what turn do you wish to draw this card?");
turnToDrawInput = (Console.ReadLine());
turnToDraw = Int32.Parse(turnToDrawInput);
turnToDraw += -1;
Console.Clear();
cardsInDeck += -turnToDraw;
frac=new Fraction (quantCardInQuestion,cardsInDeck);
Console.WriteLine("You have a " + drawProbability + " chance of drawing that card on that turn, assuming it has not yet been drawn.");
Console.ReadLine();
}
}
}
this throws several errors saying "Fraction could not be found". How can I fix this and accomplish what I am trying to achieve?
EDIT: Okay I've made several changes. Now my code throws no errors, but after running through the program, instead of saying "You have a 1/40 chance of drawing that card on that turn assuming it has not yet been drawn" it says "You have a ConsoleApplication2.Program+Fraction chance of drawing that card on that turn assuming it has not yet been drawn" My new Code goes as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApplication2;
namespace ConsoleApplication2
{
class Program
{
public class Fraction
{
private int numerator;
private int denominator;
public Fraction(int numerator, int denominator){
this.numerator = numerator;
this.denominator = denominator;
}
public int Numerator
{
get { return this.numerator; }
set { this.numerator = value; }
}
public int Denominator
{
get { return this.denominator; }
set
{
if (value == 0)
{
throw new Exception("0 denominator");
}
this.denominator = value;
}
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append(this.Numerator + "/" + this.numerator);
sb.Append(" or ");
sb.Append(this.Numerator / this.Denominator);
return base.ToString();
}
}
static string cardOrHand = "null";
static int cardsInDeck = 40;
static void Main(string[] args)
{
Console.WriteLine("Would you like to calculate card or hand probabilities? (card or hand)");
cardOrHand = (Console.ReadLine());
Console.Clear();
if (cardOrHand == "card")
{
cardProbFunction();
}
}
static void cardProbFunction()
{
string cardsInDeckInput = "40";
string quantCardInQuestionInput = "0";
string turnToDrawInput = "1";
int turnToDraw = 1;
int quantCardInQuestion = 0;
Console.WriteLine("How many cards are in the deck in question?");
cardsInDeckInput = (Console.ReadLine());
cardsInDeck = Int32.Parse(cardsInDeckInput);
Console.Clear();
Console.WriteLine("How many copies of the card in question?");
quantCardInQuestionInput = (Console.ReadLine());
Console.Clear();
quantCardInQuestion = Int32.Parse(quantCardInQuestionInput);
Console.WriteLine("On what turn do you wish to draw this card?");
turnToDrawInput = (Console.ReadLine());
turnToDraw = Int32.Parse(turnToDrawInput);
turnToDraw += -1;
Console.Clear();
cardsInDeck += -turnToDraw;
Fraction drawProbability = new Fraction(quantCardInQuestion, cardsInDeck);
Console.WriteLine("You have a " + drawProbability + " chance of drawing that card on that turn, assuming it has not yet been drawn.");
Console.ReadLine();
}
}
}