/*Hello, I am to create a program that gets a character and if it is uppercase, convert it to lowercase, if it is numeric print an error. I wrote the following code but my problem is that when I ask the user if he/she would like to quit, and I enter 'N' or 'n' the program does not get out of the while loop when it is suppose to. What am I doing wrong? Any help would be appreciated. Thanks in advanced.
#include<stdio.h>
#include<conio.h>
void toLowerCase(char);
char ch;
int main (void)
{
char ans;
do
{
char ch;
char choice;
printf("\nPlease input a character then press enter\n");
ch = getche();
if ( ch >='A' && ch <='Z' )
choice = 'U';
if ( ch >= '0' && ch <= '9' )
choice = 'N';
if ( ch >= 'a' && ch <='z' )
choice = 'L';
switch(choice)
{
case 'U':
printf("\nYou inputted %c", ch);
printf("\n!!!Upper Case character inputted!!!\n");
printf("\n\nThe program will now convert this to lowercase\n");
toLowerCase(ch);
break;
case 'N':
printf("\nYou inputted %c", ch);
printf("\n!!!Error: Numeric value inputted!!!\n");
break;
case 'L':
printf("\nYou inputted %c", ch);
break;
}
/* Below is the problem that I am facing. It does not get out of the while loop if I enter 'n' or 'N'*/
printf("\nWould you like to input another character? (y/n) : ");
ans = getche();
printf("\n");
}while ( ans != 'n' || ans != 'N' );
return 0;
}
void toLowerCase(char ch)
{
ch = ch+32;
printf("Converted value is %c", ch);
}