[Courses] C Programming For Absolute Beginners, Lesson 3: Else If, While, Operators
Leslie
leslie.brothers at verizon.net
Tue Feb 28 04:25:17 UTC 2012
On Mon, 2012-02-27 at 14:21 -0800, Carla Schroder wrote:
> Write your own 'howold' variation with three different conditions: how many
> socks in your drawer, it's your party and you will...what?, what happens when
> the price of gasoline hits various levels...it can be anything you want.
>
I decided to put the if, else-if, and else inside the while loop:
//party.c
#include <stdio.h>
int main()
{
int guests=0;
printf( "Of course you can have your party at my house! " );
printf( "How many people were you thinking of asking?\n " );
scanf ("%d", &guests);
while (guests > 12) {
if (guests > 20){
printf( "Wow, that's a lot. Can you whittle it down?\n");
}
else if (guests > 15) {
printf( "It will be a little tight but I know I'll like your
friends.\n" );
}
else {
printf( "I don't know if we can quite squeeze everyone in.\n" );
}
printf ( "How about just your closest friends? How many would that
be?\n" );
scanf ("%d", &guests );
}
printf("No problem! You know I'd do anything for you!\n\n");
return 0;
}
Thanks for this course!
-Leslie
More information about the Courses
mailing list