static void Main(string[] args) { int comp_mind = ISSMath.RNDInt(9); Console.WriteLine("In my mind=" + comp_mind); int yourguess; int count = 0; do { if (count >= 1) { Console.WriteLine("Try again"); } yourguess = ISSConsole.ReadInt("Guess the number in my mind"); ++count; } while (comp_mind != yourguess); if (count <= 2) { Console.WriteLine("Congrats. you have made {0} attempts", count); Console.WriteLine("You are a wizard"); } else if (count >= 3 && count <= 5) { Console.WriteLine("You are a good guess"); } else { Console.WriteLine("Your are lousy"); } }
static void Main(string[] args) { int a, rnd, i; i = 0; do { rnd = ISSMath.RNDInt(9); Console.WriteLine("Enter number?"); a = Convert.ToInt32(Console.ReadLine()); i++; } while (rnd != a); if (i < 3) { Console.WriteLine("Times {0}.", i); Console.WriteLine("You are a Wizard!"); } else if (i >= 3 && i < 6) { Console.WriteLine("Times {0}.", i); Console.WriteLine("You are lousy!"); } else { Console.WriteLine("Times {0}.", i); Console.WriteLine("Try Again!"); } }
public static void Ex33() { int temp; int n = ISSConsole.ReadInt("Please insert length of array: "); int[] array = new int[n]; for (int i = 0; i < n; i++) { array[i] = ISSMath.RNDInt(100); Console.Write($"\t{array[i]}"); } Console.WriteLine(); Console.WriteLine("Simplified seclection sort method progess:"); for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (array[i] < array[j]) { temp = array[i]; array[i] = array[j]; array[j] = temp; for (int l = 0; l < n; l++) { Console.Write($"\t{array[l]}"); } Console.WriteLine(); } } } }
public static void Ex22() { int RandomInteger = ISSMath.RNDInt(10); Console.WriteLine("Welcome to the Guess the Number Game!!"); Console.WriteLine("Please insert a number (0~9): "); int count = 0; int guess; do { guess = ISSConsole.ReadInt(); if (guess != RandomInteger) { Console.WriteLine("Please try again!"); count++; } else { if (count <= 1) { Console.WriteLine("You are a Wizard!"); } else if (count <= 4) { Console.WriteLine("You are a good guess!"); } else if (count <= 9) { Console.WriteLine("You are lousy!"); } } }while (guess != RandomInteger); }
public static void Ex35() { int sumClass; int[,] student = new int[12, 4]; for (int i = 0; i < 12; i++) { for (int j = 0; j < 4; j++) { student[i, j] = ISSMath.RNDInt(100); } } sumClass = 0; Console.WriteLine("\t\t\tSubject1\tSubject2\tSubject3\tSubject4\tTotal\tAverage"); for (int i = 0; i < 12; i++) { Console.Write($"Student{i + 1}"); int sum = 0; for (int j = 0; j < 4; j++) { Console.Write($"\t\t{student[i, j]}"); sum += student[i, j]; //? } Console.Write($"\t\t{sum}\t{(double)sum / 4:0.##}"); Console.WriteLine(); sumClass += sum; } Console.WriteLine(); Console.Write("Sub Average"); double[] subAverage = new double[4]; for (int j = 0; j < 4; j++) { int subSum = 0; for (int i = 0; i < 12; i++) { subSum += student[i, j]; } subAverage[j] = (double)subSum / 12; Console.Write($"\t\t{subAverage[j]:0.##}"); } Console.WriteLine(); //Find Deviation: Console.Write("Deviation"); double[] deviation = new double[4]; for (int j = 0; j < 4; j++) { double sumVariance = 0; for (int i = 0; i < 12; i++) { sumVariance += Math.Pow((student[i, j] - subAverage[j]), 2); } deviation[j] = (double)Math.Sqrt(sumVariance / 12); Console.Write($"\t\t{deviation[j]:0.##}"); } Console.WriteLine(); Console.WriteLine($"Class average: {(double)sumClass / (12 * 4):0.##}"); }
static void Main(string[] args) { int comp_mind = ISSMath.RNDInt(9); int yourguess; int count = 0; do { yourguess = ISSConsole.ReadInt("Guess the number in my mind"); ++count; } while (comp_mind != yourguess); Console.WriteLine("Congrats. your have made {0} attempts", count); }
static void Main(string[] args) { int n = 0; Console.WriteLine("Enter a number to find square root"); //Random r = new Random(); //Console.Write("Random"+r.Next(9)); n = ISSConsole.ReadInt(); int g = ISSMath.RNDInt(n); int sqrt; while (g * g != n) { g = (g + (n / g)) / 2; } sqrt = g; Console.WriteLine("The square root of {0} is {1}", n, sqrt); }
public static void Ex34() { int maxIndex = 0; int max; int n = ISSConsole.ReadInt("Please insert length of array: "); int[] array = new int[n]; for (int i = 0; i < n; i++) { array[i] = ISSMath.RNDInt(100); Console.Write($"\t{array[i]}"); } Console.WriteLine(); max = array[0]; Console.WriteLine("Refined selection sort method progess:"); for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (array[j] > max) { max = array[j]; maxIndex = j; } } //swap: array[maxIndex] = array[i]; array[i] = max; for (int l = 0; l < n; l++) { Console.Write("\t" + array[l]); } Console.WriteLine($"\tMax= {max}"); max = array[i + 1]; maxIndex = i + 1; } }
public void throwDice() { faceUP = ISSMath.RNDInt(6) + 1; }
public void Throw() { faceUp = ISSMath.RNDInt(6) + 1; }
public void Flip() { face = ISSMath.RNDInt(2); }
//Methods public void Throw() { faceUp = ISSMath.RNDInt(6) + 1; //returns random int frm 1 to 6 }
public int Throw() { faceUp = ISSMath.RNDInt(6) + 1; return(faceUp); }
public void Throw() { faceup = ISSMath.RNDInt(6); }