I found references to a c programming problem nearly identical to this one and cannot seem to find anything even remotely close to this in c++
Write a program that prompts the user to input a string. Your program should convert the
message to upper-case letters, substitute digits for certain letters (A->4, B->8, E->3, I->1, O->0,
S->5), and the append 10 or so exclamation marks.
Hint: Store the original message in char array, and then go back through the array, translating
and printing characters one by one.
I really am looking for answers as to what this is saying (A->4, B->8, E->3, I->1, O->0,S->5)
I was going to use toupper to accomplish this but am thinking that would be incorrect. I've no code as of yet and am just looking for some kind guidance. thanks in advance
Many approaches could be used here. Most common one with iteration through string and replacing letters using chained ifs or a switch works both in C++ and C. As do several other.
append 10 or so exclamation marks.
In C++ using std::string it is done in one simple line: str += "!!!!!!!!!!";
Thank you very much. I had a hand to forehead moment just now when looking at the part that reads replace A->4 etc. and I realized it was replacing letters with numbers that sort of resemble the letters. Thanks again. I'll post some code soon to show your help. again Thanks.
I got this much but haven't yet figured out how to replace the letters with digits (A->4, B->8, E->3, I->1, O->0,S->5) and when it prints out all of the blank spaces are missing.
#include <iostream>
#include <algorithm>
#include <string>
usingnamespace std;
int main()
{
int i;
char a;
char sentence[100];
cout << "Enter a string of characters to convert to uppercase and replace some characters with digits: ";
for (i = 0; a < 100; i++)
{
cin >> sentence[a];
cout << static_cast<char>(toupper(sentence[a]));
}
system("pause");
return 0;
}
#include <iostream>
#include <string>
#include <algorithm>
usingnamespace std;
int main()
{
int i;
char a;
char sentence[100];
cout << "Enter a string of characters to convert to uppercase and replace some characters with digits: ";
for (i = 0; a < 100; i++)
{
cin.get(sentence[a]);
cout << static_cast<char>(toupper(sentence[a]));
}
system("pause");
return 0;
}
I would consider that but the assignment calls for me to " Store the original message in char array, and then go back through the array, translating
and printing characters one by one." this is referring to changing the letters to digits.
If you're not willing to risk your grade, I understand.
The main problem with your code right now is that your loop is wrong. You should be using i where you are using a - in fact you don't need a for anything at all.
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int i;
char a;
char sentence[100];
cout << "Enter a string of characters to convert to uppercase and replace some characters with digits: ";
for (i = 0; i < 100; i++)
{
cin.get(sentence[a]);
cout << static_cast<char>(toupper(sentence[a]));
}
system("pause");
return 0;
}
I will repeat: you do not need the variable a for anything at all.
If your assignment did not require the use of a character array, you could do without it too. However, the assignment requires that you read in all the input first and only after that you may modify it.