Need help encrypting/decrypting a sentence. ascii

Write your question here.
c++ ascii issue. I am only able to encrypt/decrypt 1 word and my assignment is asking my to do the sentence "MEET ME AT 8." I don't know exactly where I am messing up at, please help.
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  int main()
{
	//variables
	int i, x, k, u, j;
	char str[100];
	srand((unsigned)time(NULL));
	string answer;

	header();

	do
	{
		cout << "Please enter one word:\t";
		cin >> str;

		cout << "\nPlease choose from the following options:\n";
		cout << "1 = Encrypt your word.\n";
		cout << "2 = Decrypt your word.\n";
		cin >> x;
		cin.ignore();

		cout << "\nPlease choose from the following options:\n";
		cout << "1 = Choose your own key.\n";
		cout << "2 = The computer chooses your key.\n";
		cin >> k;
		cin.ignore();

		switch (k)
		{
			//first case for encrypting a string
		case 1:

			cout << "\nPlease enter a key using a number between 1 and 35 (only): ";
			cin >> u;

		case 2:

			u = rand() % 35 + 1;
			cout << u << endl;
			break;

		default:
			cout << "\nInvalid Input !!!\n";
		}


		//using switch case statements
		switch (x)
		{
			//first case for encrypting a string
		case 1:
			for (i = 0; (i < 100 && str[i] != '\0'); i++)
				str[i] = str[i] + u; //the key for encryption is 3 that is added to ASCII value

			cout << "\nEncrypted string: " << str << endl;
			break;

			//second case for decrypting a string
		case 2:
			for (i = 0; (i < 100 && str[i] != '\0'); i++)
				str[i] = str[i] - u; //the key for encryption is 3 that is subtracted to ASCII value

			cout << "\nDecrypted string: " << str << endl;
			break;

		default:
			cout << "\nInvalid Input !!!\n";
		}

		cout << "\nWould you like to try another secret message? (yes/no) ";
		getline(cin, answer);


	} while (answer == "yes");

	cout << "\nOh, ok then...Goodbye" << endl;


	system("pause");
	return 0;
}
Well you only process one word because
1
2
cout << "Please enter one word:\t";
cin >> str;


http://www.cplusplus.com/reference/istream/istream/getline/
Try instead
1
2
cout << "Please enter one sentence:\t";
cin.getline(str,sizeof(str));
Salem c is right, "cin" is splitting the sentence you input for each space.
Registered users can post here. Sign in or register to post.