I am working on a program that validates the entered data and when I have this part of the code....
////////////////////////////////////////
do{ //validate creditrating
printf ("How is the applicant's credit rating?[G for good or B for bad]\n");
scanf ("%s", &creditrating);
if (creditrating[0] != 'g')
{
printf ("%s \n", creditrating);
printf ("Only these letters are valid: g, G, b, B \n");
printf ("How is the applicant's credit rating?[G for good or B for bad]\n");
scanf ("%s", &creditrating);
}
}while (creditrating[0] != 'g');
//////////////////////////////////////////////
the program validates and only breaks out of loop and moves on when user enters a 'g'.
but when i have this code...
///////////////////////////////////////////
do{ //validate creditrating
printf ("How is the applicant's credit rating?[G for good or B for bad]\n");
scanf ("%s", &creditrating);
if (creditrating[0] != 'g' || creditrating[0] != 'b')
{
printf ("%s \n", creditrating);
printf ("Only these letters are valid: g, G, b, B \n");
printf ("How is the applicant's credit rating?[G for good or B for bad]\n");
scanf ("%s", &creditrating);
}
}while (creditrating[0] != 'g' || creditrating[0] != 'b');
/////////////////////////////////////////////
the program doesn't ever break out of the loop even when 'g' or 'b' are entered.
I don't understand while the != will not compare when I add the or || operator to it????
Can anyone help me out here, I need to only allow letters g, G, b, B????
Jose