long int a; //number
long int b; //power
long int c; //square
int main ()
{
cout << " Enter a number ";
cin >> a;
cout << " Enter a power to raise by ";
cin >> b;
cout << " The result is ";
cin >> for( c == (a * a) * b);
system ("pause");
return 0;
} This is what I have to do:
Write a program that will ask the user for two integer numbers.
Use a for loop to raise the first number to the power of the second number.
using the long type instead of int type.
Display the answer to the screen.
And it has to come out kinda like this:
Enter a number: 5
Enter the power to raise 5 to: 3
5 to the 3 power is 125
my problem is i dont know how to or where to put a for loop in this or if I'm even doing it right plz help!!!
Using "unsigned long int" gives you more space to store your number, so you can both enter and receive extremely large numbers (till about 14 billion!).
But please note that the program has been written for Microsoft Visual Studio 2010 Ultimate.
If you are using some other compiler, just make the required changes.
By the way, there is no need for a loop as you only need to perform a single operation.
That certainly is a nice solution; however, I think that hatsumi141 has to follow the instructor's instructions. If not, then by all means, use MasterProgrammer's solution.
well, kooth,
if hatsumi141 really needs to borrow from the original program, I think using a "for" loop on the variable a until it has been multiplied with itself b times should be sufficient.
To hatsumi141:
if you want me to show you how to do that, all you have to do is ask.