Hack Forums
[Source] Print ASCII Code (C++) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Coders Lounge (https://hackforums.net/forumdisplay.php?fid=5)
+---- Thread: [Source] Print ASCII Code (C++) (/showthread.php?tid=6269094)



Print ASCII Code (C++) - Emre_ - Apr 21, 2024

Code
#include <iostream>
#include <cstdlib>

using namespace std;

void prompt();

int main()
{

    prompt();
    char ans = 'y';


    while (ans == 'y' || ans == 'Y')
    {
        cout << "Try Again(y/n)> ";
        cin >> ans;
        
        if (ans == 'y' || ans == 'Y')
        {
            prompt();

        }
        else
        {
            exit(0);
            
        }
        
            
        

    }
      
    return 0;

    
}

void prompt()
{
    char sing_ch;
    cout << "\n\n Print code (ASCII code / Unicode code etc.) of a  given character:\n";
    cout << "-----------------------------------------------------------------------\n";
    cout << " Input a character: ";
    cin >> sing_ch;

    cout << " The ASCII value of " << sing_ch << " is: " << (int)sing_ch << endl;
    cout << " The character for the ASCII value " << (int)sing_ch << " is: " << (char)((int)sing_ch) << endl << endl;

    
}