#include <stdio.h>
#include <math.h>
int main(void)
{
int x, n, a;
while (x != 0)
{
printf("please enter a number\n");
scanf_s("%d", &x);
n = 1;
if (x < 0)
{
printf("value cannot be negative\n");
}
else
{
for (a = x; a > 0; a--)
{
n = n*2;
}
printf("Two raised to the power of %d is %d\n", x, n);
}
}
return(0);
}
Wrap a for loop in a while looptrying to wrap my for loop in a while loop, getting an error.
Page 1 of 1
1 Replies - 1000 Views - Last Post: 28 October 2008 - 03:29 PM
#1
Wrap a for loop in a while loop
Posted 28 October 2008 - 02:43 PM
It is the part of the code with while that is messing up. It doesn't like the x. I'm using visual studio 2008 professional. After I build the program, it gives me a warning and no errors(the warning has to do with that "while(x !=0)" I think. So then I Start without Debugging, and an error pops up where I can Abort, Retry, or Ignore. Any ideas on how to fix this? Thanks
Replies To: Wrap a for loop in a while loop
#2
Re: Wrap a for loop in a while loop
Posted 28 October 2008 - 03:29 PM
You need to initialize x to something (other than 0) to enter the loop.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|