Write a program that prints out a simulated candle of the entered size. The program prompts the user for two positive int numbers where the first number represents the candle and the second number represents the wick.
Create a function that expects two parameters: one parameter called candleSize defines the size of the candle, and the second parameter called wickSize defines the size of the wick. The method then draws a candle with wick of the specified sizes.
Example: Candle size: 8
Wick size: 2
Output: ========–
Problem 2 Triangle
Write a program that prints a triangle of *. The program prompts the user to input a size and then prints out a triangle of that size. Create a function that expects the size parameter and prints out the triangle.
Example: Enter size: 4 Triangle:
*
**
***
****
Problem 3 Sum and Average
Write a program that calculates the average of numbers inputted by a user. The program keeps prompting a user to input a number until -1 is entered. When -1 is entered the program prints out the sum and the average of all numbers that where entered excluding -1. Round the average to two fractional digits. Introduce one function that prompts the user for input and returns a whole number inputted by the user. The functions re-prompts the user if less than -1 is entered and only returns when a valid number was entered (x >= -1). Introduce a second function that prints out the average and sum. Call both functions from the main.
Example: Number: 4
Number: -7
Invalid! Re-enter: 7
Number: 3Number: -1Sum: 14Average: 4.67 | ||||
Problem 4 | Fibonacci Numbers | 8 points |
Fibonacci numbers are a sequence of numbers where each number is represented by the sum of the two preceding numbers, starting with 0 and 1: 0, 1, 1, 2, 3, 5, 8, etc.
Write a program that repeatedly prompts the user for a positive integer and prints out whether or not that integer is a Fibonacci number. The program terminates when -1 is entered.
Create a method with the following signature. The method tests whether the number passed to it is a Fibonacci number or not. It returns true if the number is indeed a Fibonacci number and it returns false otherwise.
bool isFibonacci(int number)
Example: Input: 21
Output: 21 is a Fibonacci number
Input: 9
Output: 9 is not a Fibonacci number
Input: -1 Goodbye!
Reviews
There are no reviews yet.