using System; using System.Collections.Generic; using System.Text; namespace AaronsChallange { class Program { /// /// Will we be using Random Numbers? /// /// TRUE OR FALSE LUL static bool UseRandomNumbers() { while ( true ) { Console.WriteLine( "Use Random Numbers? y/n" ); string t = Console.ReadLine().ToLower(); if ( t == "y" ) return true; else if ( t == "n" ) return false; } } /// /// Lists the content in an INTEGER ARRAY /// /// And array of integers. static void ListIntArray( int[] intray, bool reverse ) { int[] r = new int[10]; if ( reverse ) { for ( int i = 0; i < 10; i++ ) { r[i] = intray[9 - i]; } //Reversitization } else r = intray; for ( int x = 0; x < 10; x++ ) { if ( x == 0 ) Console.Write( "[ " + r[x] + ", " ); else if ( x == 9 ) Console.Write( r[x] + " ]\n" ); else Console.Write( r[x] + ", " ); } } /// /// The main diggity shiggity /// /// static void Main( string[] args ) { Console.WriteLine( "AARON > FISH > ORANGEPNUT" ); int[] numbers = new int[10]; if ( UseRandomNumbers() ) { Random r = new Random(); for ( int i = 0; i < 10; i++ ) { numbers[i] = r.Next( 0, 10 ); } } else { int i = 0; Console.WriteLine( "Enter 10 numbers between 0-10: " ); while ( i != 10 ) { Console.Write( "Number[" + (i+1) + "]: " ); string t = Console.ReadLine().ToLower(); int x; try { x = int.Parse( t ); } catch ( FormatException ) { continue; } if ( x < 0 || x > 10 ) continue; numbers[i] = x; i++; } } ShowArray( numbers ); Console.WriteLine( "\ncan has FIND & REPLACE TIME nao?"); Console.Write( "Search for this number: " ); int s = GetInt(); Console.Write( "Replace With this Number:" ); int n = GetInt(); Console.WriteLine(); Console.WriteLine( "Number of Instances Replaced: " + CountInstancesOfANumberInAnArrayAndReturnTheCountNumberAsAnIntegerAndAlsoChangeTheInputArrayAndAaronIsAGoodTeacher( out numbers, numbers, s, n ) ); ShowArray( numbers ); Console.WriteLine( "Press any key to terminate process." ); //^_^ Console.ReadLine(); } /// /// Shows an array both reversed and normally. /// /// Number to show. static void ShowArray( int[] i ) { Console.WriteLine( "Your Numbers:" ); ListIntArray( i, false ); Console.WriteLine( "Your Numbers (REVERSED):" ); ListIntArray( i, true ); } /// /// Gets an int and makes sure it's between 0-10. /// /// User's Input as an int. static int GetInt() { int i = 0; while ( true ) { try { i = int.Parse(Console.ReadLine()); } catch ( FormatException ) { continue; } if ( i < 0 || i > 10 ) continue; break; } return i; } /// /// Counts the number of instances in this array and returns it. /// Replaces a with b. /// /// Array to do the lookup & change. /// copy of the array. /// Search number. /// Replace number. /// static int CountInstancesOfANumberInAnArrayAndReturnTheCountNumberAsAnIntegerAndAlsoChangeTheInputArrayAndAaronIsAGoodTeacher( out int[] ia, int[] iaa, int a, int b ) { int c = 0; //Count int[] t = new int[10]; ia = iaa; for ( int i = 0; i < ia.Length; i++ ) { if ( ia[i] == a ) { c++; iaa[i] = b; } else { iaa[i] = ia[i]; } } ia = iaa; return c; } } }