C Statements - ELSE!
(Page 2 of 4 )
#include <stdio.h>
#include <stdlib.h>
void main()
{
int yourmom;
int mymom;
printf("Enter your mother's weight: ");
scanf_s("%i",&yourmom);
printf("Enter my mother's weight: ");
scanf_s("%i",&mymom);
if(yourmom>mymom)
{
printf("nnnnYep...yer mom is a big fat pig.nnnnn");
}
else
{
printf("nnMy mother may be fatter...but yours is still uglyn");
}
}
This program works off of our good buddy the Else clause. Using else allows us to say: If this occurs do that, else do that. The above program works exactly as our previous program, only now if my mother is fatter than yours, it prints:
My mother may be fatter...but yours is still ugly
And of course if your mother had been fatter, it would have printed:
Yep...yer mom is a big fat pig.
Lastly, if neither condition had been true (ie; if the two values had been equal to one another), nothing would have occurred. Well never fear...we have a fix for that as well.
Next: Else...If >>
More BrainDump Articles
More By James Payne