Question: C++ Code Without chaning any code below, could anyone help me to get the second line? Ex1) Please enter a number from 3 to 100:

C++ Code

Without chaning any code below, could anyone help me to get the second line?

Ex1)

Please enter a number from 3 to 100: 6

2, 4 (<--------This is what I need - there should be no comma at the end!)

The answer is 4

Please enter a number from 3 to 100: 100

2, 4, 8, 16, 32, 64 (<-------this is what I need - no comma at the end!)

The answer is 64

#include #include #include using namespace std;

int powerOfTwo(int num);

int main () { int num; int result; int i=1; 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 pow; pow = powerOfTwo(num); cout << " The answer is "; cout << pow; cout << endl; } } int powerOfTwo(int num) { int N = num; int v = 1;

while (v <= N/2) v *= 2;

cout< return v; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!