-
about loops, i'm a n00b
hey,
i just got started on C and i already got into a problem with loops. this is what i wrote:
Code:
int main ()
{
int days, pennies;
{
printf ("days of month: ");
scanf ("%d", &days);
} while (days <28 || days>31);
}
well and if i write any number between 28 and 32 then it passes on to the next step, but i want it to loop and say "days of month" again if writing anything that isn't 28-31 but i clearly failed on that one, cuz when i type in something that isn't between those numbers nothing happens.
all thanxxx for help.
-
It looks like you want to use a "do-while()" loop ... but you're missing the "do".
For, While and Do While Loops in C - Cprogramming.com
-
With a different indentation (more like what the program does) your program looks like this:
Code:
int main ()
{
int days, pennies;
{
printf ("days of month: ");
scanf ("%d", &days);
}
while (days <28 || days>31);
}
Your program is composed of 1 block and 1 (empty) loop. You probably wanted a "do ... while" loop.