Nesting if else statements?
Code:
/*============================================================================
Description:Write a program to ask the user for the names of three runners and
the time it took each of them to finish a race.
=============================================================================*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HW3
{
class Program
{
static void Main(string[] args)
{
string NameOne, NameTwo, NameThree;
int TimeOne, TimeTwo, TimeThree;
Console.Write("Please enter the name of runner number 1: ");
NameOne = Console.ReadLine();
Console.Write("Please enter the time of runner number 1: ");
TimeOne = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter the name of runner number 2: ");
NameTwo = Console.ReadLine();
Console.Write("Please enter the time of runner number 2: ");
TimeTwo = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter the name of runner number 3: ");
NameThree = Console.ReadLine();
Console.Write("Please enter the time of runner number 3: ");
TimeThree = Convert.ToInt32(Console.ReadLine());
if ((TimeOne < TimeTwo) && (TimeOne < TimeThree))
{if (TimeTwo > TimeThree)
Console.WriteLine("The Winner is " + NameOne);
Console.WriteLine("Second Place is " + NameThree);
Console.WriteLine("Third Place is " + NameTwo);
}
else if ((TimeOne < TimeTwo) && (TimeOne < TimeThree))
{
if (TimeTwo < TimeThree)
Console.WriteLine("The Winner is " + NameOne);
Console.WriteLine("Second Place is " + NameTwo);
Console.WriteLine("Third Place is " + NameThree);
}
I don't think this is nested correctly because when you enter this:
Please enter the name of runner number 1: Bob
Please enter the time of runner number 1: 2
Please enter the name of runner number 2: Frank
Please enter the time of runner number 2: 3
Please enter the name of runner number 3: Dana
Please enter the time of runner number 3: 5
Second Place is Dana
Third Place is Frank
Press any key to continue...
Any ideas on how to correct my if statements? :freak:
|