Ask Question
2 January, 16:13

The Beaufort Wind Scale is used to characterize the strength of winds. The scale uses integer values and goes from a force of 0, which is no wind, up to 12, which is a hurricane. Write a script that generates a random force value between 0 and 12, with use of randi command, Then, it prints a message regarding what type of wind that force represents. The answers should follow this pattern:

+2
Answers (1)
  1. 2 January, 17:26
    0
    See explaination

    Explanation:

    Script by switch statement

    random_force = randi (12) switch (random_force) case 0 disp ("There is no wind") case {1,2,3,4,5,6} disp ("there is a breeze") case {7,8,9} disp ("there is a gale") case {10,11} disp ("it is a storm") case 12 disp ("Hello Hurricane!") end

    First it generates a random force between 1 and 12

    Then the switch statement is executed according to the force

    in case values of corresponding force are written and their string will be printed according to the case which depends upon the value of random_force

    Multiple case values are used because we need multiple values to print the same string

    So values {1,2,3,4,5,6}, {7,8,9},{10,11} are combined into one case becuse they all have same value

    Script by using nested if-else

    random_force = randi (12) / /It will genrate a random force value between 1 and 12 which can be used further if random_force = = 0 disp ("There is no wind") elseif (random_force > 0) && (random_force 6) && (random_force 9) && (random_force < 12) disp ("it is a storm") elseif random_force = = 12 disp ("Hello Hurricane!") end

    First if will check if force is zero and will print its corresponding string

    Second, elseif will check if force is between 1 and 6 and will print its corresponding string

    third elseif will check if force is between 7 and 9 and will print its corresponding string

    Fourth elseif will check if force is 10 or 11 and will print its corresponding string

    Last else if will compare value to 12 and return the corresponding string
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “The Beaufort Wind Scale is used to characterize the strength of winds. The scale uses integer values and goes from a force of 0, which is ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers