Answer to Question #199416 in C# for Nkhululeko Chabala

Question #199416

The Saffir-Sampson Hurrican Scale classifies hurricanes into 5 categories numbered 1 to 5. Write a program that asks the user to input the wind speed. Pass the wind speed to a method that determines and returns the hurricane category. Your Main() method must display the relevant category. The different categories is classified as follows: Category Sustained wind speed in km/h 5 252 or higher 4 209 - 251 3 178 - 208 2 154 - 177 1 119 - 153 Any storm with wind speed of less than 119 km/h is not a hurricane.


1
Expert's answer
2021-05-30T07:10:22-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace Q199416
{
    class Program
    {
        static void Main(string[] args)
        {
            int windSpeed;
            //asks the user to input the wind speed. 
            Console.Write("Enter the wind speed: ");
            windSpeed = int.Parse(Console.ReadLine());
            int category= determineHurricaneCategory(windSpeed);
            if (category != 0)
            {
                Console.WriteLine("\nThe hurricane category is: {0}\n", category);
            }
            else {
                Console.WriteLine("\nStorm with wind speed of less than 119 km/h is not a hurricane.\n");
            }
            


            Console.ReadLine();
        }


        static int determineHurricaneCategory(int windSpeed)
        {
            //Category Sustained wind speed in km/h 
            //5 252 or higher
            if (windSpeed >= 252) {
                return 5;
            }
            //4 209 - 251
            if (windSpeed >= 209 && windSpeed <= 251)
            {
                return 4;
            }
            //3 178 - 208
            if (windSpeed >= 178 && windSpeed <= 208)
            {
                return 3;
            }
            //2 154 - 177
            if (windSpeed >= 154 && windSpeed <= 177)
            {
                return 2;
            }
            //1 119 - 153 
            if (windSpeed >= 119 && windSpeed <= 153)
            {
                return 1;
            }
            //Any storm with wind speed of less than 119 km/h is not a hurricane.
            return 0;
        }
    }
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS