I am kind of new creating the A1Z26 cipher generator. But this has a problem.
Only the program generates the last two numbers. What's wrong?
#include <iostream>
#include <ostream>
#include <string>
using namespace std;
int i; // Counter
char str1[101]; // A string of characters for generator.
string str2, str3; // Adds a string
string str4; // Generated number.
int nochar; // Number of characters.
int a1z26()
{
for (int i = 0; i < nochar; i++)
{
if (str1[i] == 'a')
{
str2 = "1-";
}
if (str1[i] == 'b')
{
str2 = "2-";
}
if (str1[i] == 'c')
{
str2 = "3-";
}
if (str1[i] == 'd')
{
str2 = "4-";
}
if (str1[i] == 'e')
{
str2 = "5-";
}
if (str1[i] == 'f')
{
str2 = "6-";
}
if (str1[i] == 'g')
{
str2 = "7-";
}
if (str1[i] == 'h')
{
str2 = "8-";
}
if (str1[i] == 'i')
{
str2 = "9-";
}
if (str1[i] == 'j')
{
str2 = "10-";
}
if (str1[i] == 'k')
{
str2 = "11-";
}
if (str1[i] == 'l')
{
str2 = "12-";
}
if (str1[i] == 'm')
{
str2 = "13-";
}
if (str1[i] == 'n')
{
str2 = "14-";
}
if (str1[i] == 'o')
{
str2 = "15-";
}
if (str1[i] == 'p')
{
str2 = "16-";
}
if (str1[i] == 'q')
{
str2 = "17-";
}
if (str1[i] == 'r')
{
str2 = "18-";
}
if (str1[i] == 's')
{
str2 = "19-";
}
if (str1[i] == 't')
{
str2 = "20-";
}
if (str1[i] == 'u')
{
str2 = "21-";
}
if (str1[i] == 'v')
{
str2 = "22-";
}
if (str1[i] == 'w')
{
str2 = "23-";
}
if (str1[i] == 'x')
{
str2 = "24-";
}
if (str1[i] == 'y')
{
str2 = "25-";
}
if (str1[i] == 'z')
{
str2 = "26-";
}
if (str1[i] == ' ')
{
str2 = " ";
}
str3.swap(str2);
}
str4 = str2 + str3;
return 0;
}
int main()
{
cout << "A1Z26 cipher generator." << endl;
cout << "Generates a string of characters into numbers." << endl << endl;
return1:
cout << "Enter the string (up to 100 characters, no numbers):\n";
cin.getline(str1, 101);
if (str1[101] == '0' && str1[101] == '1' && str1[101] == '2'&& str1[101] == '3'&& str1[101] == '4'&& str1[101] == '5'&& str1[101] == '6'&& str1[101] == '7'&& str1[101] == '8' && str1[101] == '9')
{
goto return1;
}
cout << endl;
_strlwr_s(str1); // Transforms the letters in a string to all lower-case letters.
nochar = strlen(str1);
a1z26();
cout << "Your generated number: " << endl;
cout << str4 << endl <<endl;
cout << "Share this to your friends to decode your mystery!" << endl;
system("pause");
return 0;
}