Hello, I am attempting a program that gathers a password from the user, and then creates and displays a new password, given the following rules: All vowels in the original password should be replaced with 'X', All of the characters should be reversed, and all numbers should be replaced with the letter 'Z'. I am close to the program, but I can't seem to figure out how to replace all of the numbers without making a bunch of if statements that seems very inefficient. Any help would be much appreciated.
/* Joe ; C++
*/
#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
usingnamespace std;
int main()
{
// All vowels in the original password should be replaced with 'X',
// All of the characters should be reversed, and all numbers should
//be replaced with the letter 'Z'.
string pw;
int vCheck;
int numCheck;
string xVowels = "aeiou";
string zNumbers = "1234567890";
cout<<"Please enter password" <<endl;
getline(cin,pw);
cout<<"The stuff you entered is: " <<pw <<endl;
cout<<"The string is " <<pw.length() <<" characters long!" <<endl;
//Reverse pw
reverse(pw.begin(), pw.end());
cout <<"reversed " <<pw <<endl;
// Changes all vowels to X, Changes all # to Z
for (int y = 0; y <= pw.length()-1; ++y){
for (int a = 0; a <=xVowels.length()-1; ++a){
vCheck = xVowels.at(a);
if (pw.at(y) == xVowels.at(a)){
pw.at(y) = 'x';
}
if (pw.at(y) == zNumbers.at(a)){
pw.at(y) = 'Z';
}
}
}
cout <<"New PW with reverse and replaced stuff = " <<pw <<endl;
return 0;
}
// Changes all vowels to X, Changes all # to Z
for (char& ch : pw) // for each char in pw
{
if (xVowels.find(ch) != string::npos)
{
ch = 'X';
}
elseif (zNumbers.find(ch) != string::npos) // or use isdigit from <ctype>
{
ch = 'Z';
}
}