Skip to content

Instantly share code, notes, and snippets.

@m-HARD
Last active March 16, 2019 19:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m-HARD/42eda09a2a3ed1e7d39341e49efb55e4 to your computer and use it in GitHub Desktop.
Save m-HARD/42eda09a2a3ed1e7d39341e49efb55e4 to your computer and use it in GitHub Desktop.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
void F_char_t_int() {
string name;
cout << "\nEnter the text\n";
getline(cin, name);
for (char x : name)
{
char value = tolower(x);
for (int i = 97; i < 97 + 26; i++)
if ((int)value == i)
{
cout << i - 96 << " ";
break;
}
else if (x == ' ')
{
cout << "| ";
break;
}
}
cout << "\n" << name;
}
void F_int_T_char() {
string name;
int num;
cout << "\nEnter the num (remember you can separate names by \'|\')\n";
getline(cin, name);
num = (name[0] - 48) * 10 + name[1] - 48;
//cout << name[0] << " " << name[1] << " " << name[2] << " " << num << " " << name.length();
name.push_back(' ');
name.push_back(' ');
for (int i = 0; i < name.length(); i++)
{
num = 0;
for (int j = 0; j < 3; j++)
if (name[i] == ' ')
break;
else if (name[i] == '|')
{
num = 10000;
break;
}
else if (name[1 + i] == ' ')
{
num = name[i] - 48;
break;
}
else if (name[2 + i] == ' ')
{
num = (name[i] - 48) * 10 + name[i + 1] - 48;
i++;
break;
}
else if (name[3 + i] == ' ')
{
num = (name[i] - 48) * 10 + name[i + 1] - 48;
i += 2;
cout << "E";
break;
}
else {
num = 20000;
}
if (num == 20000)
cout << "E";
else if (num == 10000)
cout << " ";
else if (num == 0)
cout << "";
else
for (int i = 97; i < 97 + 26; i++)
{
if (i - 96 == num)
{
cout << (char)i;
break;
}
}
}
}
int main()
{
musab:
char go;
cout << "\npress 1 to go (from_char_to_int) or 2 to go (from_int_to_char)\t";
go = getch();
if (go == '1') {
F_char_t_int();
}
else if (go == '2')
F_int_T_char();
else cout << "\nsorry we can\'t understand this";
char n_y;
cout << "\nenter y to replay the program or n to exit";
n_y = getch();
if (n_y == 'y')
goto musab;
getch();
return 0;
}
/*
*/
//#include "stdafx.h"
#include <iostream>
#include <string>
#include <conio.h>
#include <cstdlib>
using namespace std;
//if you use v.studio remove all comment
/* void F_char_t_int() {
string name;
cout << "\nEnter the text\n";
getline(cin, name);
for (char x : name)
{
char value = tolower(x);
for (int i = 97; i < 97 + 26; i++)
if ((int)value == i)
{
cout << i - 96 << " ";
break;
}
else if (x == ' ')
{
cout << "| ";
break;
}
}
cout << "\n" << name;
}
*/
void F_int_T_char() {
string name;
int num;
cout << "\nEnter the num (remember you can separate names by \'|\')\n";
getline(cin, name);
num = (name[0] - 48) * 10 + name[1] - 48;
//cout << name[0] << " " << name[1] << " " << name[2] << " " << num << " " << name.length();
name.push_back(' ');
name.push_back(' ');
for (int i = 0; i < name.length(); i++)
{
num = 0;
for (int j = 0; j < 3; j++)
if (name[i] == ' ')
break;
else if (name[i] == '|')
{
num = 10000;
break;
}
else if (name[1 + i] == ' ')
{
num = name[i] - 48;
break;
}
else if (name[2 + i] == ' ')
{
num = (name[i] - 48) * 10 + name[i + 1] - 48;
i++;
break;
}
else if (name[3 + i] == ' ')
{
num = (name[i] - 48) * 10 + name[i + 1] - 48;
i += 2;
cout << "E";
break;
}
else {
num = 20000;
}
if (num == 20000)
cout << "E";
else if (num == 10000)
cout << " ";
else if (num == 0)
cout << "";
else
for (int i = 97; i < 97 + 26; i++)
{
if (i - 96 == num)
{
cout << (char)i;
break;
}
}
}
}
int main()
{
musab:
char go;
cout << "\npress 1 to go (from_char_to_int) or 2 to go (from_int_to_char)\t";
go = getch();
if (go == '1')
;//F_char_t_int();
else if (go == '2')
F_int_T_char();
else cout << "\nsorry we can\'t understand this";
char n_y;
cout << "\nenter y to replay the program or n to exit";
n_y = getch();
if (n_y == 'y')
goto musab;
getch();
return 0;
}
@khatabwedaa
Copy link

ما شغال

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment