Hello everyone! I just started to learn how to program using C, and was given an assignment I cannot solve. I really need help !!
I have to create a program that
1) changes an ASCII code entered by the user into the appropriate letter.
2)changes a character entered in by the user into ASCII code
3) Display an ASCII TABLE
4) and when the letter "q" is entered, the program ends...
I'm sorry it may be a little confusing, but this is what I was able to come up with so far.
CODE
#include <stdio.h>
int main(){
int i;
char c,type;
printf("ASCII character program\n\n");
printf("Input 1, 2, 3, or q\n");
printf("1: ASCII code -> CHAR\n");
printf("2: CHAR -> ASCII code\n"); *This is the menu thats
printf("3: DISPLAY ASCII TABLE\n"); suppose to loop until
printf("q: End of this Program\n"); q is entered
scanf("%d",&type);
while(type!=113){
if(type=49){
printf(" ASCII code -> CHAR \n");
printf(" input ASCII code\n");
scanf("%d",&i);
printf(" Character for ASCII code %d is -> '%c'\n\n", i,i);}
if(type=50){
printf(" CHAR -> ASCII code \n");
printf(" input a Character\n");
scanf("%c",&c);
printf(" ASCII code for character '%c' is -> '%d'\n\n", c,c);}
if(type=51){
printf("ASCII code table for 1-127\n");
for(i=1; i<=127; i++)
printf("Character for ASCII code %d is -> '%c'\n",i,i);}
}
}
I need it to keep repeating the menu at the top, until the user enters "q" after the menu. Sorry for the unclearness but any comment will be helpful.. thanks in advance.
To make it more clear, I want the program to work out like in this example
I want it to work out like this..
QUOTE
ASCII character program
Input 1,2,3, or q
1: ASCII code -> CHAR
2: CHAR -> ASCII code
3: Display ASCII TABLE
q: End of this program
1
input ASCII code
123
Character for ASCII code 123 is -> '{'
Input 1,2,3, or q
1: ASCII code -> CHAR
2: CHAR -> ASCII code
3: Display ASCII TABLE
q: End of this program
2
input a character
r
ASCII code for character 'r' is -> 114
Input 1,2,3, or q
1: ASCII code -> CHAR
2: CHAR -> ASCII code
3: Display ASCII TABLE
q: End of this program
q
This is just an example of how I want the program to work, but I can't seem to get the looping part right...please HELP!!!!
Edit: please use a descriptive title. ~VThis post has been edited by Videege: 13 Apr, 2007 - 11:06 PM