Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,114 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,757 people online right now. Registration is fast and FREE... Join Now!




ASCII manipulation

 
Reply to this topicStart new topic

ASCII manipulation

siren128
13 Apr, 2007 - 09:02 PM
Post #1

New D.I.C Head
*

Joined: 13 Apr, 2007
Posts: 18


My Contributions
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. ~V

This post has been edited by Videege: 13 Apr, 2007 - 11:06 PM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: ASCII Manipulation
14 Apr, 2007 - 05:09 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
You can simply move the while loop so it begins above the menu display.
User is offlineProfile CardPM
+Quote Post

marmar44@hotmail.com
RE: ASCII Manipulation
15 Apr, 2007 - 03:23 PM
Post #3

New D.I.C Head
*

Joined: 15 Apr, 2007
Posts: 1


My Contributions
hey siren i have the same problem too i have an assignment that is hexadecimal calculator that will use the ASCII numbers to read what the user is entering,but we are using liked list, do u have any suggestions?
User is offlineProfile CardPM
+Quote Post

siren128
RE: ASCII Manipulation
17 Apr, 2007 - 05:10 AM
Post #4

New D.I.C Head
*

Joined: 13 Apr, 2007
Posts: 18


My Contributions
hey, i been working on the program for a while but no luck... its no good.. I seriously need help
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: ASCII Manipulation
17 Apr, 2007 - 05:28 AM
Post #5

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
Did you try the suggestion given?
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 09:48PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month