I'm really happy you asked me to post my code, because when I went back over it, it didn't work at all. Now I have two problems that I don't know how to fix. First off, when I run the program and enter breed of dog, I get all three names for the dog instead of just the one. Second, the program loops just fine, but will not terminate when flag is changed to anything else. Let me know what you guys see wrong.
Code:
/* Dog naming program */
#include <stdio.h>
int main (void)
{
char gender, breed, temp, flag; /* declaration */
flag = 'Y';
while( flag = 'Y' ) {
/* processing phase */
printf( "Let's pick out a name for your dog.\n" ); /* prompt */
printf( "What gender is your dog? Enter 'm'\n");
printf( "for male and 'f' for female: " );
scanf( "%d", &gender ); /* read gender */
temp = getchar (); /* clear char */
printf( "What breed of dog do you have?\n" ); /* prompt */
printf( "Enter 'c' for Collie, 's' for\n" );
printf( "St. Bernard and 'd' for Dalmation.\n" );
scanf( "%d", &breed ); /* read breed */
temp = getchar (); /* clear char */
if ( gender = 'm' ) {
if ( breed = 'c' )
printf( "Try naming your dog Weinberg.\n" );
if ( breed = 's' )
printf( "Try naming your dog Gunther.\n" );
if ( breed = 'd' )
printf( "Try naming your dog Spots.\n" );
}
else {
if ( breed = 'c' )
printf( "Try naming your dog Rosie.\n" );
if ( breed = 's' )
printf( "Try naming your dog Heidi.\n" );
if ( breed = 'd' )
printf( "Try naming your dog Princess.\n" );
}
/* termination phase */
printf( "Would you like me to try to give\n" ); /* prompt */
printf( "a dog a new name? 'Y' or 'N'?\n" );
scanf( "%c", &flag ); /* read flag */
temp = getchar (); /* clear char */
}
return 0;
}