C++ School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

C++ Source Code


Welcome to Dream.In.Code
Become a C++ Expert!

Join 300,293 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,130 people online right now. Registration is fast and FREE... Join Now!





Convert characters into a ASCII value and vice versa

Inputs a number -> outputs a character Inputs a character -> outputs a number

Submitted By: DeeViLiSh
Actions:
Rating:
Views: 53,601

Language: C++

Last Modified: August 31, 2006

Snippet


  1. #include <iostream.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.         int number;
  7.         char letter;
  8.         int option;
  9.  
  10.  
  11.  
  12.         cout<<"Convert ASCII numbers into characters and vice versa";
  13.         cout<<endl<<"[1] * ASCII -> ABC"
  14.                 <<endl<<"[2] * ABC -> ASCII"
  15.                 <<endl<<"[3] * EXIT"<<endl;;
  16.  
  17.         cin>>option;
  18.         switch (option) //Detects the option
  19.                {
  20.                 case 1:
  21.                         cout<<"Enter a number : ";
  22.                         cin >> number; //Inputs the number
  23.                         cout<<"The number you entered is : \""<<char(number)<<"\" in ASCII"<<endl; //Ouputs the same number in char
  24.                         break;
  25.  
  26.                 case 2:
  27.                         cout<<"Enter a letter : ";
  28.                         cin >> letter; //Inputs the letter
  29.                         cout<<"The character you entered is : \""<<int(letter)<<"\" in ASCII"<<endl; //Outputs the same letter in int
  30.                         break;
  31.  
  32.                 case 3:
  33.                         return 0;
  34.  
  35.                 default: //If user chooses anything else besides options given
  36.                         cout<<"Invalid Option!";
  37.                         system("PAUSE");
  38.                         break;
  39.                 }
  40.  
  41.         system("PAUSE");
  42.         return 0;
  43. }
  44.  
  45.  
  46.  

Copy & Paste


Comments


Jupiter 2008-10-01 12:11:42

Works like a charm... ppl using VS 2005/2008 Professional/Express Edition 1. must change to 2. add => using namespace std; before main

failngrade 2009-03-13 21:54:19

I am a beginner and this is my first attempt to convert a DAT file that I opened in Note Pad with your snippet. Please assist me further if possible, Thanks.

Mejamz 2009-03-15 11:00:57

I added using namespace std; to get the cin & cout to work...code ran smooth and converted fine each character or integer entered


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month