I have this code, it reads in a text file and stores it in a string[] called 'sh2VolumeData', it contains lots of numbers. So to cater for the integers I have tried to convert the string[] to a int[] so that my bubblesort can sort them. However, when I try to run my code I get the same error message saying that the input is in the incorrect format.
Any ideas why? Thanks.
The error occurs when I input "volume" into the cmd to go to the else if statement.
PLEASE NOTE - SOME OF MY CODE COMMENTS ARE NOT CORRECT.
else if(input2.ToLower() == "volume") //If the user types 'day', they will be directed here. They can then choose between the unsorted array or the sorted array.
{
int[] intSh2VolumeData = new int[sh2VolumeData.Length];
for (int x = 0; x < sh2VolumeData.Length; x++)
{
intSh2VolumeData[x] = Convert.ToInt32(sh2VolumeData[x]);
}
Console.Write("To view this Array unsorted, input 'un', to see this Array sorted input 's'.");
string input3 = Console.ReadLine();
if(input3.ToLower() == "un")
{
Console.WriteLine("\n");
Console.WriteLine("UNSORTED");
for (int i = 0; i < intSh2VolumeData.Length; i++)
Console.Write(intSh2VolumeData[i] + "\n");
}
else if(input3.ToLower() == "s")
{
int temp = 0;
for (int write = 0; write < intSh2VolumeData.Length; write++)
{
for (int sort = 0; sort < intSh2VolumeData.Length - 1; sort++)
{
if (intSh2VolumeData[sort] > intSh2VolumeData[sort + 1])
{
temp = intSh2VolumeData[sort + 1];
intSh2VolumeData[sort + 1] = intSh2VolumeData[sort];
intSh2VolumeData[sort] = temp;
}
}
}
Console.WriteLine("\n\n\nSORTED");
for (int i = 0; i < intSh2VolumeData.Length; i++)
Console.Write(intSh2VolumeData[i] + "\n");
Console.WriteLine("\nMax Value"); //144
Console.WriteLine(intSh2VolumeData[143]);
Console.WriteLine("\nMin Value"); //1
Console.WriteLine(intSh2VolumeData[0]);
}
else if(input3.ToLower() != "a" || input3.ToLower() != "d")
{
Console.WriteLine("\nSorry, Please enter 'un' or 's' next time.");
}
}
Aucun commentaire:
Enregistrer un commentaire