[Courses] C Programming For Absolute Beginners, Lesson 3: Else If, While, Operators

Emily Gonyer emilyyrose at gmail.com
Thu Mar 1 12:55:23 UTC 2012


//books you have

#include <stdio.h>

int main()
{
int book=0;
int book2=0;
int book3=0;

printf( "Please enter how many books you have.");
scanf( "%d", &book );
printf( "So, you have %d books.", book);

while ( book < 10 ){
printf( "Books are good! But is that all you have? Please enter how many
books you have.\n" );
scanf( "%d", &book );
printf( "OK, so you have %d books.", book);
}
if ( book > 50 ){
printf( "Awesome! I love books too!\n" );
}
else if ( book > 11 ){
printf( "Books are good! You can never have too many you know!\n" );
}
return 0;
}

Hey there, after much playing this is what I've come up with :)

Emily

On Tue, Feb 28, 2012 at 1:51 PM, Carla Schroder <carla at bratgrrl.com> wrote:

> 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
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> _______________________________________________
> Courses mailing list
> Courses at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/courses
>



-- 
Whatever you can do, or dream you can, begin it. Boldness has genius, power
and magic in it. -  Goethe

Be who you are and say what you feel because those who mind don't matter
and those who matter don't mind. - Dr.Seuss

Not everything that can be counted counts, and not everything that counts
can be counted. - Albert Einstein


More information about the Courses mailing list