TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ryan Hennis
NA
1
0
can't convert readline to int32
Jun 7 2009 2:19 PM
I have been working on this for school but I am stumped. It runs but it says that it can't convert the readline to int32. I believe I have it coded right but it keeps giving me the error after I choice anything. Here is the code if someone could please tell what I did wrong. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ControlStructure { class ControlStructure { static int[] largeArray; // Declared array for largest number. static int[] lowArray; // Declared array for lowest number. static void Main(string[] args) { char choice; // Declares choice variable. int laCounter; // Declares lacounter variable. int counter; // Declares counter variable. int numbers; // Declares numbers variable. int input; // Declares input variable. largeArray = new int[500]; // I just intialized the array to 500 for this. lowArray = new int[500]; // Same as Above. Console.Write( "Welcome to this weeks assignment" ); // Displays Welcome message. Console.WriteLine(); // Skip a line. Console.WriteLine( "Please choose from the following choices" ); // Prompts user to decide. Console.WriteLine( "A - Find the largest # with a known quantity of numbers" ); // Displays choice A. Console.WriteLine( "B - Find the smallest # with an unknown quantity of numbers" ); // Displays choice B. Console.WriteLine( "C - Quit" ); // Displays choice C. choice = Convert.ToChar( Console.Read() ); // Reads user input and stores in choice. while ( choice != 'C' ) // Checks for the quit command. { switch ( choice ) // Switch statement to determine which choice was made. { case 'a': case 'A': { Console.Write( "Please enter the amount of numbers " ); Console.WriteLine( "you wish to process : " ); // Prompts the user for amount of numbers. laCounter = 0; laCounter = Convert.ToInt32(Console.ReadLine()); // Converts line to int and stores in laCounter. Console.WriteLine(); // Skip a line. Console.WriteLine( "You may enter the numbers now." ); // Prompts user to enter numbers. numbers = Convert.ToInt32(Console.ReadLine()); // Converts line to int and stores in numbers. for (int i = 0; i <= laCounter; i++) // For loop to navigate array. { largeArray[i] = (numbers); // Stores numbers in largeArray. } // End for statement. // Method call. Console.WriteLine( "The largest number is {0}", GetMaximum() ); break; } // End Case. case 'b': case 'B': { Console.Write ( "Please enter -999 when you have " ); Console.WriteLine ( "finished inputting numbers." ); // Informing the user to use the sentinal to stop. Console.WriteLine(); // Skip a line. Console.WriteLine( "Please enter your first number : " ); // Prompt user for number. input = Convert.ToInt32(Console.ReadLine()); while ( input != -999) // Check for sentinal { for (counter = 0; counter <= 500; counter++) { input = lowArray[counter]; } // Prompting user for another number. Console.WriteLine ( "Please enter another number or -999 : " ); input = Convert.ToInt32(Console.ReadLine()); // Coverts line to int and stores in input. } // End while. // Method call. Console.WriteLine ( "The lowest number is {0}", GetMinimum() ); break; } // End Case. default: { Console.Write( "Please select either A, B, C." ); break; } } // End switch. } // End while. Console.WriteLine("Thank you using this program."); // Displays good-bye message. } // End Main. public static int GetMaximum() // Method to find largest number in an array. { int large = largeArray[0]; // Declared large to be largeArray. foreach (int larger in largeArray) // Looks through large. { if (larger > large) // Comparing large to largest. large = larger; // If large is more than largest stores it in largest. } // End foreach. return large; // Returns the biggest int entered. } // End GetMaximum. public static int GetMinimum() // Method to find lowest number in an array. { int low = lowArray[0]; // Declared low to be lowArray. foreach ( int lower in lowArray ) // Look though low for lowest int. { if ( lower < low ) // Compares low and lowest. low = lower; // If low is less than lowest stores low in lowest. } // End foreach. return low; // Returns the lowest int input. } // End GetMinimum. } // End Class ControlStucture. } // End namespace.
Reply
Answers (
2
)
How to watch youtube video from C# win application
passing data between components