Decisions if elseif else Problems

Problem 1

Write Lua code that asks the user for a number in the range of 1 through 7. Display the corresponding day of the week where

  • 1 for Monday

  • 2 for Tuesday

  • 3 for Wednesday

  • 4 for Thursday

  • 5 for Friday

  • 6 for Saturday

  • 7 for Sunday.

  • If the user enters a number outside the range of 1 - 7, print “error, out of range”.

Problem 2

Write Lua code that asks a user for the day of the week in English and translates it to Spanish.

English

Spanish

Sunday

Domingo

Monday

Lunes

Tuesday

Martes

Wednesday

Miercoles

Thursday

Jueves

Friday

Viernes

Saturday

Sabado

If the user enters a word other than the ones above, print Invalido.

Problem 3

Write Lua code that asks a user what year they were born in and then prints their Chinese Zodiac symbol.

Year

Chinese Zodiac

1996

Rat

1997

Ox

1998

Tiger

1999

Rabbit

2000

Dragon

2001

Snake

2002

Horse

2003

Goat

2004

Monkey

2005

Rooster

2006

Dog

2007

Pig

Problem 4

Write Lua code that asks a user to enter a number from 1 through 10. The program should display the Roman numeral version of that number.

Number

Roman Numeral

1

I

2

II

3

III

4

IV

5

V

6

VI

7

VII

8

VIII

9

IX

10

X

If the number is outside of this range, print "we’ll work on that problem later".

Problem 5

What's your Zodiac sign? Write Lua code that asks the user for their month and day of birth. Print the user's Zodiac sign according to the chart:

Zodiac Sign

Date Range

Capricorn

December 22 to January 19

Aquarius

January 20 to February 18

Pisces

February 19 to March 20

Aries

March 21 to April 19

Taurus

April 20 to May 20

Gemini

May 21 to June 20

Cancer

June 21 to July 22

Leo

July 23 to August 22

Libra

September 23 to October 22

Scorpio

October 23 to November 21

Sagittarius

November 22 to December 21

Problem 6

Write Lua code that asks a user how much money they spend at the store sale.

  • If they spend $75 or less, they receive no discount.

  • If the user spends $75 or more, they receive $15 off.

  • If the user spends $100 or more, they receive $25 off.

  • If they user spends $150 or more, they receive $50 off.

Print the total of the order.

Problem 7

Write Lua code that asks a user how much money they spend at the store sale. The sale is:

  • 15% off $250+

  • 20% off $500+

  • 25% off $1000+

They will not receive a discount if they order less than $250.

Print the total of the order.

Problem 8

Write Lua code that asks the user for a letter. If the user enters a, e, i, o or u, the print "You entered a vowel", otherwise print "You entered a consonant".

Problem 9

The length of a month varies from 28 to 31 days. Write Lua code that asks the users to enter a month and print the number of days in the month. Print "28 or 29 days" for February.

Problem 10

Write Lua code that asks the user the lengths of each side of a triangle. Print a message if the triangle is equilateral, isosceles or scalene.