encypt

how in this program can i make it encrypt all words you enter not just 1

#include <iostream>
#include <cstring>
#include <string>
using namespace std;

int main()
{
cout << "enter a password you want to encrypt,it has to be only letters: ";
cout << endl;
string c;
cin >> c;
for (int i = 0; i<c.size();i++)
{
c[i] = tolower(c[i]);
c[i] = c[i]-2;
if (c[i]<97)
{c[i] = c[i]+26;}
}
cout << c << endl;
system("pause");
return 0;
}
Last edited on
Instead of cin >> c; use getline(cin, c);.
i did that and it worked but when i ran the program and entered the sentence but every where there was a space their was and 8 so say i put hi i am moot it says "fg8g8yk8kyrr" how do i get rid of the 8

#include <iostream>
#include <cstring>
#include <string>
using namespace std;

int main()
{
cout << "enter a password you want to encrypt,it has to be only letters: ";
cout << endl;
string c;
getline(cin, c);
for (int i = 0; i<c.size();i++)
{
c[i] = tolower(c[i]);
c[i] = c[i]-2;
if (c[i]<97)
{c[i] = c[i]+26;}
}
cout << c << endl;
system("pause");
return 0;
}
Last edited on
??
closed account (D80DSL3A)
You really can't think of a way to solve that problem? Make an exception for blank characters in the string:
1
2
3
4
5
6
7
if( c[i] != ' ' )
{
     c[i] = tolower(c[i]);
      c[i] = c[i]-2;
      if (c[i]<97)
          c[i] = c[i]+26;
}
what do u mean.do i add thhat to this.


#include <iostream>
#include <cstring>
#include <string>
using namespace std;

int main()
{
cout << "enter a password you want to encrypt,it has to be only letters: ";
cout << endl;
string c;
getline(cin, c);
for (int i = 0; i<c.size();i++)
{
c[i] = tolower(c[i]);
c[i] = c[i]-2;
if (c[i]<97)
{c[i] = c[i]+26;}
}

cout << c << endl;
system("pause");
return 0;
}
??
closed account (D80DSL3A)
It replaces the code inside your for loop.
Topic archived. No new replies allowed.