no answer after request of an user input

I'm doing this for a class, but I'm having a bit of a problem which after I input the 5 digits in the compiler, it will only play nnnnn instead of what I'm looking for.
This is what is requested: Using a while loop, generate the password in a new string variable by reversing the order of the character in the string and subtracting 15 from each character to produce the password.

so if I type p for example it should display a

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  #include <iostream>
#include <string>

using namespace std;

int main() {
	string inputi;
	int a[5];//input 5 numbers
	int b[5];//generated result

	cout << "          -----------------------------" << endl;
	cout << "          's Password Generator" << endl;
	cout << "          -----------------------------" << endl;

	cout << "\nPlease enter a 5 character word in order to generate a password: ";
	cin >> inputi;

	if (inputi.length() != 5) {//If not 5 characters word it prints an error message}
		cout << "ERROR! ErRoR! NoT a 5 ChArAcTeR wOrD. " << endl;
		cout << "Thanks for using 's Password Generator" << endl;
			return 1;
	}
	//storing the characters
	a[0] = inputi[0] - 15;
	a[1] = inputi[1] - 15;
	a[2] = inputi[2] - 15;
	a[3] = inputi[3] - 15;
	a[4] = inputi[4] - 15;

	for (int i = 0; i < 5; i++) {//subtract by 15
		a[i] = (a[i] - 15);
		b[i] = a[(i - 15)];
	}

	cout << "Your password is " << (char)(b[4] + (int)'0') << (char)(b[3] + (int)'0') << (char)(b[2] + (int)'0') << (char)(b[1] + (int)'0') << (char)(b[0] + (int)'0') << endl << endl;
	cout << "Thanks for using 's Password Generator! " << endl;
	return 0;
I'm doing this for a class, but I'm having a bit of a problem which after I input the 5 digits in the compiler, it will only play nnnnn instead of what I'm looking for.

From ASCII table, digits and alphabet characters are different. You should treat them differently.

Digits have lower values comparing to alphabet characters, so it is not good that you directly subtract the characters directly with 15.
closed account (1vRz3TCk)
I've only given it a quick look but on line 32 the subscript for a[] is going out of bounds. I would assume you intended something more like line 31
b[i] = (a[I] - 15);
Ah, I made a mistake as I had to do this with the while loop
Topic archived. No new replies allowed.