In: Computer Science
I NEED THIS IN PSEUDOCODE:
SWITCH/CASE 2 - Complete the pseudocode below by including a SWITCH statement that takes the user input (an integer between 26-30) and prints out a count up in its English equivalent. For example: if the user inputs “26”, the code will print “twenty-six”, “twenty-seven” on the next line, and so on up to “thirty”. If the user inputs “30”, the code will print “thirty” and finish.
CREATE inputNum
PRINT ("Please enter a number between 26-30 to start counting from:")
READ inputNum
WHILE inputNum >= 26 AND inputNum <= 30
BEGIN WHILE
Answer :
CREATE inputNum
PRINT ("Please enter a number between 26-30 to start counting from :")
READ inputNum
WHILE inputNum >=26 AND inputNum <=30
BEGIN WHILE
SWITCH STATEMENT
CASE based on inputNum
CASE 26:
PRINT("twenty-six")
PRINT("\ntwenty-seven")
PRINT("\ntwenty-eight")
PRINT("\ntwenty-nine")
PRINT("\nthirty")
BREAK
CASE 27:
PRINT("twenty-seven")
PRINT("\ntwenty-eight")
PRINT("\ntwenty-nine")
PRINT("\nthirty")
BREAK
CASE 28:
PRINT("twenty-eight")
PRINT("\ntwenty-nine")
PRINT("\nthirty")
BREAK;
CASE 29:
PRINT("twenty-nine")
PRINT("\nthirty")
BREAK;
CASE 30:
PRINT("thirty")
BREAK
END SWITCH STATEMENT
END WHILE
Converting pseudo code into c program :
#include <stdio.h>
int main(void)
{
int inputNum;
printf("Please enter a number between 26-30 to start counting from :");
scanf("%d",&inputNum);
while(inputNum >=26 && inputNum <= 30)
{
switch(inputNum)
{
case 26:
printf("twenty-six");
printf("\ntwenty-seven");
printf("\ntwenty-eight");
printf("\ntwenty-nine");
printf("\nthirty");
break;
case 27:
printf("twenty-seven");
printf("\ntwenty-eight");
printf("\ntwenty-nine");
printf("\nthirty");
break;
case 28:
printf("twenty-eight");
printf("\ntwenty-nine");
printf("\nthirty");
break;
case 29:
printf("twenty-nine");
printf("\nthirty");
break;
case 30:
printf("thirty");
break;
}
break;
}
return 0;
}
Output :