Answered step by step
Verified Expert Solution
Link Copied!

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

  1. 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 }
      1. Ask the user to enter a number (an integer)
      2. Take the users number and determine if this number can be found in the Fibonacci sequence.
      3. Show a message to the user whether it is or isnt in the sequence.
      4. 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
  2. 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: f  Enter 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

What is the principle of thermodynamics? Explain with examples

Answered: 1 week ago

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago