I'm a little bit confused on using If , Else if on my current project...I need to compare 6 values, the smallest one should be prompted by a message box..here's my code
if ((sort1 > sort2) || (sort1 > sort3) || (sort1 > sort4) || (sort1 > sort5))
{
MessageBox.Show("The Best Sorting Technique Algorithm is Insertion Sort with the time of " + elapsedMs1 + " ms");
}
else if ((sort2 > sort1) || (sort2 > sort3) || (sort2 > sort4) || (sort2 > sort5))
{
MessageBox.Show("The Best Sorting Technique Algorithm is Selection Sort with the time of " + elapsedMs2 + " ms");
}
else if ((sort3 > sort1) || (sort3 > sort2) || (sort3 > sort4) || (sort3 > sort5))
{
MessageBox.Show("The Best Sorting Technique Algorithm is Bubble Sort with the time of " + elapsedMs3 + " ms");
}
else if ((sort4 > sort1) || (sort4 > sort2) || (sort4 > sort3) || (sort4 > sort5))
{
MessageBox.Show("The Best Sorting Technique Algorithm is Merge Sort with the time of " + elapsedMs4 + " ms");
}
else if ((sort5 > sort1) || (sort5 > sort2) || (sort5 > sort3) || (sort5 > sort1))
{
MessageBox.Show("The Best Sorting Technique Algorithm is Quick Sort with the time of " + elapsedMs5 + " ms");
}
But it will not prompt the smallest number on the messagebox. Do this have a much proper coding rather than using if, else if? I've also tried using AND but it doesn't work too..
elseat the end of the chain to see?