Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What is wrong with my code? QUESTION: Ask the user for a number between 3 and 100 (inclusive). USING LOOPS, figure out what is the

What is wrong with my code?

QUESTION:

Ask the user for a number between 3 and 100 (inclusive). USING LOOPS, figure out what is the largest power of 2 that is less than or equal to the number entered. For example, if the user entered 6, answer would be 4. If the user entered 100, the answer would be 64. You must do this within a function called powerOfTwo. For example:

Please enter a number from 3 to 100: 100 The answer is 64 

MY CODE:

#include #include #include

using namespace std; int powerOfTwo(int); int main() { int num; cout>num; cout 100)) cout

int powerOfTwo(int a) { int i; int power=2; int previous; while(power

} return previous; }

Output and Expected output:

image text in transcribed

1 Compare output Input 6 Please enter a number from 3 to 100: 6 Your output The answer is 4 Please entes a number Erom 3 to 100:6 Please enter a number from 3 to 100: 6 2, 2, 4 The answer is 4 Expected output 2. Compare output Input 100 Please enter a number from 3 to 100: 100 Please enter a number from 3 t100: 10 Your output The answer is 64 Please enter a number from 3 to 100: 100 Expected output 2, 4, 8, 16, 32, 64 Tne answer 13 04 wer is 64

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

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions