Times Table
This project will be a cli app to calculate the times table with a given range.
- Ask times table number from user e.g. “1”
- Ask for a range e.g. “1-12” to calculate
- Extra: if no range is given default to “1-12”
- Output times table in a easily readable format e.g. “1 x 1 = 1”
- Extra: make output look like a table
- Extra: handle input errors
- Create variable to store times table number
- Choose a int type if your language is statically typed
- Name it
times_table
- Output “
Enter times table:
” to the console - Accept input from console, converting to a int and storing into
times_table
- Create a variable to store the range input
- Choose a string type if your language is statically typed
- Name it
table_range
- Output “
Enter range (e.g. 1-12):
” to the console - Accept input from console storing into
table_range
- Create a variable
- Choose an string array/list type, if a length is needed use 2
- Name it
table_range_split
- Split the
table_range
, using “-
” as the separator, store result intable_range_split
- Create two variables
- Choose a int type if your language is statically typed
- Name them
start
andend
- Convert index 0 of
table_range_split
into a int and store instart
- Convert index 1 of
table_range_split
into a int and store inend
- Output message saying what the selected times table is, including the selected range
- Create a for loop; this should use a range from the
start
stop
variables- Create variable
- Choose a int type if your language is statically typed
- Name it
result
- Multiply
times_table
withi
and store inresult
- Output times table result
- Create variable
- Program finished
Once completed test your code with some data, if it does not work try having a look at a working example solution and compare your code.
Please be aware example solutions may not look the same as your code, as there are many different ways of implementing the solution(s).
Enter table number: 2
Enter range (e.g. 1-12): 1-5
Times Table For 2, 1-6:
1 x 2 = 2
2 x 2 = 4
3 x 2 = 6
4 x 2 = 8
5 x 2 = 10
- Implement the steps indicated with “Extra”
- Take a look at the example solutions, you could learn how to write it in a different language