- Joined
- Aug 10, 2004
- Messages
- 10,285
- Age
- 39
- Location
- Sweden
- Nation Banner

- Main Job

- Secondary Job

- Third Job

- Server
- Fenrir
- Linkshell
- Avaritas
- FFXIV
- Uzor
ok... I have a project due Friday, where we're supposed to make "cyphered messages". Basically, the user is supposed to be able to insert a number, and then the program will generate numbers based on user input.
Example: User inputs the number 3.
The program generates 3 random numbers between 0 to 9.
Those part works fine, even though I'll look through them later to make it work better. The thing is, I can't get it to cypher a message you input. I was thinking you need to use the string.size() function in order to count the lenght of the word, and then use a for-loop to loop through each of the numbers 1 at a time and add the number to the letter. An example would be a + 3 = d. Since c++ supposedly follows the ascii standard, I'd figure the number a(97) would become 100. The problem is, that it obviously isn't as simple as that, for more then 1 reason
First being that z would become }, and Z would become ]. Second is that I can't even get it to translate the letter a and b correctly.
Help appreciated ~.~ if I don't get this to work by Friday I'll fail ; ;
Yes, the code is incomplete. I've worked 1 step at a time, and I got stuck on the last part, so I haven't completet it yet <.<;
The problem lies in the cypher() function, btw, so you don't have to read through it all xD
Example: User inputs the number 3.
The program generates 3 random numbers between 0 to 9.
Those part works fine, even though I'll look through them later to make it work better. The thing is, I can't get it to cypher a message you input. I was thinking you need to use the string.size() function in order to count the lenght of the word, and then use a for-loop to loop through each of the numbers 1 at a time and add the number to the letter. An example would be a + 3 = d. Since c++ supposedly follows the ascii standard, I'd figure the number a(97) would become 100. The problem is, that it obviously isn't as simple as that, for more then 1 reason
First being that z would become }, and Z would become ]. Second is that I can't even get it to translate the letter a and b correctly.
Help appreciated ~.~ if I don't get this to work by Friday I'll fail ; ;
Code:
#include <iostream> // Loading library containing cout
#include <ctime> // Loading library containing rand()
#include <string> // Loading the library containing string, size etc.
using namespace std;
void menu();
void cypher();
int main()
{
menu();
int choice;
cin >> choice;
while(choice != 3){
switch (choice)
{
case 1 : cypher();
break;
case 2 : 2;
break;
case 3 : cout << "quit";
break;
default : cout << "That option does not exist. Please chose another one.";
}
menu();
cin >> choice;
}
}
void menu() // Function which creates the menu.
{
cout << "Type in a number corresponding to the choices below.\n"
"1) Generate a new cypher message.\n"
"2) Decypher a cyphered message.\n"
"3) Quit\n";
}
void cypher() // Function which lets you cypher the word
{
int length;
string word;
srand((unsigned)time(NULL));
int ckey[10];
cout << "How many numbers do you want the cypher key to be? ";
cin >> length;
cout << "\nYour numbers are: ";
for (int i=1; i<=length; i++)
{
ckey[i] = rand() % 10; // Generates a number between 0 to 9 and saves them
cout << ckey[i] << ", ";
}
cout << "\n\nEnter message you wish to be cyphered: ";
cin >> word;
cout << "\nCyphered, your message is the following: ";
for (int i=0; i<= word.size()-1; i++)
{
word[i] = word[i] + ckey[i];
}
cout << word << endl;
}
The problem lies in the cypher() function, btw, so you don't have to read through it all xD