i need to change some character into numbers for example:
I = 1
R = 2
E = 3
A = 4
S = 5
G = 6
T = 7
B = 8
P = 9
O = 0
input example: HELLO IM GOOD
output example: H3LL0 1M G00D
Are you trying to make us do your homework?
Anyhow, there are multiple possibilities.
You can convert to a string and use it's methods as such:
string s;
s="HELLO IM GOOD"
s.replace('I,'1')
s.replace('R,'2')
.
.
.
cout << s; //print solution
This code helps:)
#include <iostream>
#include<stdio.h>
using namespace std;
int main() {
string s;
getline (cin, s); //used to get string input with spaces
string s1 = "OIREASGTBP";
string s2 = "0123456789";
for (int i=0; i<s.size(); i++)
{
int a = s1.find(s[i]);
if(a != -1)
{
s[i] = s2[a];
}
}
cout<<s;
}