I am trying to write a program that gives you 3 options:
1 for encryption
2 for decryption
3 Exits the program
If option 1, my program will ask for a password, an input file name and an output file name. My program will then read the file and mesh it with the password resulting in an encrypted file. It will write this file out.
If option 2, my program will ask for the password and the encrypted file name. Read the file and perform a decryption, printing the decryption on the screen
If option 3, the program will stop.
My problem is that my program is giving me 3 errors:
1)syntax error : 'return'
2)'encrypt' : function does not take 2 arguments
3)'decrypt' : function does not take 2 arguments
I gave your code a one-over. I might have missed some stuff, but this is the stuff I noticed. Also... get in the habit of indenting properly. Indentation makes code much easier to read.
line 1: #include "stdafx.h"
This isn't really an error, but MSVS likes to put in this stdafx crap by default. Break the habit. When you start a new project, check the "empty project" box, then you don't need the stdafx nonsense, and other people will be able to more easily compile your code.
line 15: void main(){
main should always return an int. Not a void. You'll also have to change the return on line 26 to return 0;
line 23: elseif (choice += 3)
I think you meant >=... not +=
line 64: out_stream<<
What are you trying to do here? You can't leave the << hanging like this. I'd remove the entire else block (delete lines 63,64)
line 68: out_stream.put(encrypt("projcpp.txt","ranNum"));
You're trying to call 'encrypt' with two strings, but encrypt does not take two strings -- it doesn't take any parameters at all. It also doesn't return anything, so you can't put it inside of a put() call like this either.
Unless you have another function called encrypt somewhere -- but it's not visible to this program.
line 102: out_stream.put(decrypt("ciphertext_out.txt",k));
Same problem. decrypt doesn't take any parameters, but you're giving it two. It also doesn't return anything, so you can't put it in put() like this.
main should always return an int. Not a void. You'll also have to change the return on line 26 to return 0;
As Irwin of CEF states, "ISO compliance has no direct implication for how main should be handled in regards to declaration/returning." A void function has no defined return value, therefore it is simply the last usage of EAX. Given this information, there's nothing wrong with using void main(), simply that almost all programmers are taught to use "int main()" from their first hello world program.
This is your code: encrypt("projcpp.txt","ranNum");
This attempts to call a function called encrypt -- but such a function doesn't exist! What are you trying to accomplish with this code? Is there another function called encrypt that you forgot to write?
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
usingnamespace std;
void do_again(),direction(int ans);
void option_1(),option_2(),option_3();
int main()
{
do_again();//calls do_again function
return 0;
}//end function
void do_again()
{
int ans;//this will be used every time
do
{ //User menu
cout << "Hello and welcome.\n\n";
cout << "Please choose one of the following.\n";
cout << "1: Encryption\n";
cout << "2: Decryption\n";
cout << "3: Exit\n";
cin >> ans;
cin.ignore(80,'\n'); //this reads what the user chose
direction(ans);//sends the answer to direction
}while(ans!=3);//program keeps going until the user chooses exit
}//end of this function
void direction(int ans)
{
switch (ans)//Go through the options
{
case 1:
option_1();
break;
case 2:
option_2();
break;
case 3:
option_3();
break;
default://If anything other than 1,2,3 is chosen
cout << "The option you have chosen was not listed, please try again.\n";
break;
}
}//end of case functions
void option_1() //If option 1 is choosen, encryption begins
{
char a[5000];
char pw[15];
char buffer[256];
int x,y;
int i,j;
int choice=4;
ifstream examplefile ("c:\\proj3cpp.txt");
if (! examplefile.is_open())
{
cout << "Error opening file";
exit (1);
}
while (! examplefile.eof() )
{
examplefile.getline (buffer,100);
cout << buffer << endl;
}
cout<<endl<<"Please enter a password: "; //User inputs a password
cin>>pw;
x=strlen(a);
y=strlen(pw);
j=0;
for (i=0; i<x; i++)
{
if (j>=y) j=0;
a[i]=a[i]+pw[j];
}
cout<<endl<<a;
cout<<endl<<"Encryption is now complete and has been saved to a text document.\n\n";
}
void option_2()// If option 2 is chosen, decryption begins
{
}
void option_3()// If option 3 is chosen, program closes.
{
}