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

What is wrong with the following two functions? void Power ( int x, int y) { int

ID: 3609825 • Letter: W

Question

What is wrong with the following two functions?
void Power ( int x, int y) { int result;
result = 1;
while ( y > 0 )
{ result = result * x;
y--;
}
}
and ...
void Power ( int& x, int& y, int&result) { result = 1;
while (y > 0)
{
result = result * x;
y--;
}
}
void Power ( int x, int y) { int result;
result = 1;
while ( y > 0 )
{ result = result * x;
y--;
}
}
and ...
void Power ( int& x, int& y, int&result) { result = 1;
while (y > 0)
{
result = result * x;
y--;
}
}

Explanation / Answer

void Power ( int x, int y) { int result;
result = 1;
while ( y > 0 )
{ result = result * x;
y--;
}
} problems
1. It is only for Integers not double values.
2. The result is not returned from the function.
3. Can't Be used for negative power.


and ...
void Power ( int& x, int& y, int&result) { result = 1;
while (y > 0)
{
result = result * x;
y--;
}
}
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote