can get user assigned varables

Hey, I'm making a program that encrypts a phrase using a Ceaser cipher on which the key or offset is variable. I have very very little experience and I'm stuck on having the user input the to veriables.

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
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int key = 0;// number of spaces to shift text

    string input;// phrase to encrypt
    int count = 0, length;

    cout << "Enter an integer from 1-26 as your key ";
    cin >> key;
    cout << "Your offset value is: " << key <<endl;

    cout << "Enter your phrase: \n";
    getline(cin, input);

    length = (int)input.length();

    for (count = 0; count < length; count++)
    {
        if (isalpha(input[count]))
        {
            input[count] = tolower(input[count]);
            for (int i = 0; i < key; i++)
            {
                if (input[count] == 'z')
                    input[count] = 'a';
                else
                    input[count]++;
            }
        }
    }

    cout << "Results: \n" << input << endl;

}

  Put the code you need help with here.
1
2
cin >> key; 
cin.ignore();
so it discards the line break that you pressed after writing the number
Topic archived. No new replies allowed.