[Courses] C Programming For Absolute Beginners, Lesson 3: Else If, While, Operators
Carla Schroder
carla at bratgrrl.com
Tue Feb 28 18:51:38 UTC 2012
Now that was fun! Because the first few times I tried to compile this it
freaked out with lots of errors. I finally figured out that copying it from
email inserted a couple of line breaks where there should not have been line
breaks. Got rid of those and it ran perfectly. Thanks Leslie!
Carla
On Monday, February 27, 2012 08:25:17 PM Leslie wrote:
> 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
>
> _______________________________________________
> Courses mailing list
> Courses at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/courses
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Carla Schroder
ace Linux nerd
author of Linux Cookbook,
Linux Networking Cookbook,
Book of Audacity
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More information about the Courses
mailing list