trouble with for loop and ASCII encryption; just about done

So I have all this code and just one more thing to figure out. I have to input text. Then text is output as written, in all lower, all upper and then in ASCII encryption where '~' is ' ' (space bar) and vice versa with 'O' being the same value. This encryption takes into acccount all characters on Keyboard. My problem is that this encryption takes the all uppercase iteration instead of original input. Here is code: try using a(should be =, instead it is ]). Thanks here is code.
/*
File: p02
Name: Thomas Rollins
Date: 2/23/09
Course: CS 140-002
Desc: Write a program that displays user input as
Originally written; in all lower case; in all Upper case; in previous encryption
*/
#include <iostream>
#include <string>
using namespace std;
int chars;
int main()
{
string input;
string line="------------------------------------------------------------";
string ASCIIDECRY;
char x,y;
cout << "Programmed by " << endl << endl;
cout << "Enter some text and I will encrypt it. Do not press the enter " << endl;
cout << "until you are done." << endl << endl;
getline(cin, input);
cout << endl << endl << line << endl;
for (chars = 0; chars <= input.length(); chars++) //Initializes int chars at 0
{ //and states when total input is greater
cout << input[chars]; //then sum of characters run for loop
if(chars >1 && chars%59 == 0) //Prevents first character from having own line
cout << endl;
} //Also any character over 59 starts new line and
cout << endl << line << endl << endl << line << endl; //will go from 0-59 characters before it repeats function and
for(chars=0; chars <= input.length(); chars++) //starts new line
{
{if (input[chars] >= 'A' &&input[chars] <= 'Z') //This says that when upper case letter appear
input[chars] = input[chars]+' ';} //to run simple program to convert to lowercase
cout<<input[chars];
if (chars > 1 && chars%59 == 0)
cout << endl;
}
cout << endl << line << endl << endl << line << endl;
for(chars=0; chars <= input.length(); chars++)
{
{if (input[chars] >= 'a' &&input[chars] <= 'z') //Same as above but finds lower case letters
input[chars]= input[chars]-32;} //and make them upper case
cout<<input[chars];
if (chars > 1 && chars%59 == 0)
cout << endl;
}

cout << endl << line << endl << endl << line << endl;

for(chars = 0; chars <= input.length(); chars++)
{
//States range of inputable characters
x = input[chars]; //convert input into shorter variable and
y = x + '^' - '~'; //perform decryption algorithm
ASCIIDECRY = '~' - x;
cout << ASCIIDECRY;
if (chars > 1 && chars%59 == 0)
cout << endl;
}
cout << endl << line << endl << endl;
}
[code] tags please.
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
#include <iostream>
#include <string>
using namespace std;
int chars;
int main()
{
string input;
string line="------------------------------------------------------------";
string ASCIIDECRY;
char x,y;
cout << "Programmed by " << endl << endl;
cout << "Enter some text and I will encrypt it. Do not press the enter " << endl;
cout << "until you are done." << endl << endl;
getline(cin, input);
cout << endl << endl << line << endl;
for (chars = 0; chars <= input.length(); chars++) //Initializes int chars at 0
{ //and states when total input is greater
cout << input[chars]; //then sum of characters run for loop
if(chars >1 && chars%59 == 0) //Prevents first character from having own line
cout << endl;
} //Also any character over 59 starts new line and 
cout << endl << line << endl << endl << line << endl; //will go from 0-59 characters before it repeats function and 
for(chars=0; chars <= input.length(); chars++) //starts new line
{
{if (input[chars] >= 'A' &&input[chars] <= 'Z') //This says that when upper case letter appear
input[chars] = input[chars]+' ';} //to run simple program to convert to lowercase
cout<<input[chars];
if (chars > 1 && chars%59 == 0)
cout << endl;
}
cout << endl << line << endl << endl << line << endl;
for(chars=0; chars <= input.length(); chars++)
{
{if (input[chars] >= 'a' &&input[chars] <= 'z') //Same as above but finds lower case letters
input[chars]= input[chars]-32;} //and make them upper case
cout<<input[chars];
if (chars > 1 && chars%59 == 0)
cout << endl;
}

cout << endl << line << endl << endl << line << endl;

for(chars = 0; chars <= input.length(); chars++)
{
//States range of inputable characters
x = input[chars]; //convert input into shorter variable and
y = x + '^' - '~'; //perform decryption algorithm
ASCIIDECRY = '~' - x;
cout << ASCIIDECRY;
if (chars > 1 && chars%59 == 0)
cout << endl;
}
cout << endl << line << endl << endl;
}
Indentation please.
Topic archived. No new replies allowed.