Answer:
See explaination
Step-by-step 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 < 7) disp("there is a breeze") elseif (random_force > 6) && (random_force < 10) disp("there is a gale") elseif (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