/* * Project2.c * Chapter 6 * By John Stile * Purpose: Write a short program that asks the user for a character, * uppoer or lower case. * a) If the character is neigher uppoer or lower case, run a function * that reminds them of the request, and obtains a new character, * checking that character. * If the character is either uppor or lower case, return the character. * If it is not, say "goodbye" and exit. * b) If the character is uppercase, output lower case equivalent. * c) If the character is lowercase, output uppercase equivalent. */ #include // include libary functions when compiling. int main(void) // header for function main. takes nothing, returns an int. { char cc; // declare character variable cc printf ("Please enter a character (upper or lower case): "); // prompt for input cc=getchar(); // get a char from standard in, assign to location of vairable cc. if ( cc > 122 || cc < 65 ) // if cc does not cointain an uppoer or lower case char { getchar(); // clean buffer printf("Enter a character (upper or lower case): ");// prompt them one more time cc=getchar(); // get a char from standard in, assign to location of vairable cc. if ( cc > 122 || cc < 65 ) // if cc does not cointain an uppoer or lower case char { printf("goodbye\n"); // after second attemp exit return 1; // return exit status 1 to calling program } } else { printf("You entered: %c\n", cc); // print what they typed in. } if ( cc > 97 ) // lowercase numbers are 97 to 122 { printf("The uppercase letter is %c\n", cc-32 ); // print uppercase ascii character of cc } else { printf("The lowercase letter is %c\n", cc+32 ); // print lower case ascii character of cc } return 0; // return exit status 0 to calling program }