Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <iostream> #include <string> using namespace std; /* Type your code her

ID: 3857511 • Letter: #

Question

#include <iostream>

#include <string>

using namespace std;

/* Type your code here. */

int main()

{

int num;

cout << "Please enter a number from 3 to 100: ";

cin >> num;

cout << num << endl;

if ((num < 3) || (num > 100))

cout << "Please follow the directions!" << endl;

else {

int answer = powerOfTwo(num);

cout << "The answer is " << answer << endl;

}

}

12.8 Problem 12.1 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 2, 4, 8, 16, 32, 64 The answer is 64 LAB ACTIVITY 12.8.1: Problem 12.1 10 19 main.cpp Load default template... 1 #include 2 #include 3 using namespace std; 4 5 Type your code here.* 7 int mainO) 9 int num; 10 cout num; 12 cout

Explanation / Answer

Answer: modified code here.

#include <iostream>
#include <string>
using namespace std;

/* Type your code here. */
int powerOfTwo(int num){
int num2 = 2;
while(num2 <= num ){
num2 = num2*2;
}
return num2/2;
  
}


int main()
{
int num;
cout << "Please enter a number from 3 to 100: ";
cin >> num;
cout << num << endl;
if ((num < 3) || (num > 100))
cout << "Please follow the directions!" << endl;
else {
int answer = powerOfTwo(num);
cout << "The answer is " << answer << endl;
}
}