Question
// This code is written in C#...instead of using else if statements i need it to use arrays, the code works just fine and is
//This code is written in C#...instead of using "else if" statements i need it to use arrays, the code works just fine and is a console application.
using System;
namespace VariableDefinition
{
class Program
{
static void Main()
{
int i;
int max = int.MinValue;
bool going = true;
while (going)
{
Console.WriteLine("Enter wind speed=");
string s = Console.ReadLine();
if (s == "q" || s == "Q")
break;
i = Convert.ToInt32(s);
if (max < i)
max = i;
if (i <= 0)
{
Console.WriteLine("Invalid input!");
}
else
{
if (i < 74)
{
Console.WriteLine("tropical storm not a typhoon");
}
else if ((i >= 74) && (i <= 95))
{
Console.WriteLine("Category 1 with 70 mph");
}
else if ((i >= 96) && (i <= 110))
{
Console.WriteLine("Category 2 with 110 mph");
}
else if ((i >= 111) && (i <= 130))
{
Console.WriteLine("Category 3 with 175 mph");
}
else if ((i >= 131) && (i <= 155))
{
Console.WriteLine("Category 4 with 131 mph");
}
else if (i >= 156)
{
Console.WriteLine("Category 5 with 170 mph");
}
Console.WriteLine("Highest wind speed was " + max);
}
}
}
}
}
//This code is written in C#...instead of using "else if" statements i need it to use arrays, the code works just fine and is a console application.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started