Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Description The purpose of this challenge is to various flow looping and control structures. This challenge displays a menu and asks the user to perform
Description
The purpose of this challenge is to various flow looping and control structures. This challenge displays a menu and asks the user to perform various tasks.
Requirements
- Show a menu to the user with the following choices: a, b, c, q (Show the menu once and use a do-while statement to prompt the user for a menu command):
- a Display all odd numbers between n1 and n2.
- Ask the user to enter two numbers, n1 and n2, using the int data type.
- Using any looping mechanism (determine which loop works best), display all odd numbers between n1 and n2
- b Determine if a number is in the Fibonacci sequence (Wiki, Pop Culture references: The Davinci Code, 21) . The Fibonnacci sequence starts with the numbers 1 and 1. The next number in the sequence is the sum of the preceding two numbers. In this case, 1 + 1 = 2. The 3rd term is 2. Now we have 1, 1, 2. The next term adds 1 + 2 = 3. The first few terms of the sequence looks like 1, 1, 2, 3, 5, 8, 13, 21, 34, etc.
int term1 = 1; int term2 = 1; int next = term1 + term2; while (some boolean expression) { // set new values for term1, term2 and next according // to Fibonacci }
- Ask the user to enter a number (an integer)
- Take the users number and determine if this number can be found in the Fibonacci sequence.
- Show a message to the user whether it is or isnt in the sequence.
- HINT: Write a loop that generates the successive terms of the Fibonacci sequence. If terms generated exceed the number youre determining without having matched your search number, then the number is not in sequence
- c The sum of all integers between n1 and n2 inclusively
- Ask the user to enter two numbers, n1 and n2, using the int data type.
- Using any looping mechanism (determine which loop works best), calculate the sum of all numbers between n1 and n2
- q Quit the program
- a Display all odd numbers between n1 and n2.
- Make sure your switch statement contains a default statement to cover the case when the user selects an unsupported menu option
Sample Interaction / Output
a - Display all odd b - Is number in Fibonacci? c - Sum of numbers between 1 and 10 q - Quit Enter a command: fEnter a command: a Enter a number: 1 Enter a number: 10 ALL ODD: 1 3 5 7 9 Enter a command: b Enter a number: 5 5 is in the Fibonacci sequence Enter a command: b Enter a number: 11 11 is not in the Fibonacci sequence Enter a command: c Enter a number: 1 Enter a number: 10 SUM: 55 Enter a command: q
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started