Hi there! i'm trying to create a basic encrypting program that will just change letters. example: a to c and so on. I have written the code on to my visual studio 2010 no errors or warning. But when i start the program and type in something, nothing happens heres the code:
#include <iostream>
#include <stdlib.h>
#include <sstream>
#include <string>
#include "windows.h"
usingnamespace std;
void encrypt(string words);
bool tester(int x, int y);
bool testerfor(int x, int y);
int main()
{
string Emptywords;
cout << "What shall i encrypt?" << endl;
cin >> Emptywords;
encrypt(Emptywords); // calling encryption funtion and passing user input
}
void encrypt(string words)
{
char A [100]; //char array for letters that user typed in
char B [100]; //char array for encrypted letters
string encrypt; //string that will contain in the end the encrypted message
for(int n = 0; testerfor(n,words.size()); ) // this for loop is going to encrypt the letters
{
int b = 1;
A[n] = words[b]; // words[n] = checking for what letters user entered
switch(A[n]) // switch statement to encrypt the letter that A array has
{
case'a':
B[n] = 'c'; // putting the encrypted letter inside B array
break;
case'b':
B[n] = 'd';
break;
case'c':
B[n] = 'e';
break;
case'd':
B[n] = 'g';
break;
case'e':
B[n] = 'j';
break;
case'f':
B[n] = 'l';
break;
case'g':
B[n] = 'รถ';
break;
case'h':
B[n] = 'a';
break;
case'i':
B[n] = 'k';
break;
case'j':
B[n] = 'y';
break;
}
stringstream ss; // the part that will but encrypted message inside ecrypt
ss << B[n]; // be should contain encrypted letter
if(tester(n,words.size()))
{
ss >> encrypt;
}
n++; // increasing n by 1
b++; // increasing b by 1
}
cout << encrypt << endl; // showing the result to the user
Sleep(1000);
}
bool tester(int x, int y)
{
if (x == y)
{
returntrue;
}
returnfalse;
}
bool testerfor(int x, int y)
{
if (x < y)
{
returntrue;
}
returnfalse;
}
after typing in all my letters and pressing enter it should print on the screen the encrypted message but it dosen't.
what am i doing wrong any ideas?
Homework or not, the OP has at least shown some effort. All I did was show him/her a simpler way, whether the OP learns anything from it is up to him/her.
kbw. its not an homework...
as soon as I ask a question everybody goes like "its his homework do not help him!"
im only trying to get better at c++ because after learning c++ i will start to learn SDL and opengl.
what the point of this forum if you cant ask a question and only get answers like
"its hes homework! do it yourself!" .. and so on!