Help in excuting loops.
Posted on 1998-04-10
I am presently learning the (for, while and do while) loops. My problem is my program stays in a continuous
loop and I have to shut down the computer to restart. I am new at this, so please be patient. I have this program
to write, representing the letters (A thru Z) and (a thru z) to coresspond to the digits (2 thru 9) on the telephone. Yes, I was here earlier with the same question, only using the ( if and if else) and I did get it to work.
Now my code starts:
char ch=' ' ;
printf("Enter a single letter, and I will tell you what the corresponding digit is on the telephone \
(Period to stop). ");
while(ch>='A' && ch<='C' || ch>='a' && ch<='c')
printf("\nThe digit 2 correspondes to the letter %c on the telephone.", ch);
while(ch>='D' && ch<='F' || ch>='d' && ch<='f')
printf("\nThe digit 3 correspondes to the letter %c on the telephone.", ch);
ETC. ETC. ETC.
Then a statement to show any invalid characters that are entered, such as,
while(ch<'A' && ch>' / ' || ch<' ' ' && ch>'z')
printf(\nThe entry %c is invalid.",ch);
while(ch !=' . ')
Can you please help? I can't get the program to print the users input and loop back to ask for the users input
again. All I get is a continous loop of the first input. Also, will any digits entered ( 0 thru 9) show up in the printf as invalid characters since I am using ch? Thanks for any help you can provide. Dan (Beginner)