I'm new to these boards, and to C++ so I look forward to learning something new. Anyhow I've been working on this coding for a rudementry encryption/decryption program for awhile now and I seem to be stuck. Here is the code...
My goal is to be able to have users select either decrypt or encrypt then have the program call on the specific function to do what the user wants. But for some reason no matter what the user inputs, it always defaults to the encryp function. What am I doing wrong here? Thank you in advance.
If you put semicolon right after an if statement it treats that as an empty statement and will do nothing if the condition is true. The code that comes after will not be part of the if statement so it will always run.
So now when I make a selection, it outputs the correct cout statement in the function but it no longer continues. Meaning now it wont even call upon the correct function...Grrrr so frustrating!
you are passing variable m in function char getmenuselection (char m) as pass by value.So the changes done for variable m will not reflect back to main function.
So after function call "getmenuselection(menu);" the value of menu is still zero.That is the reason why correct function is not being called.
You can either pass variable m as pass by reference
or you can get the value of menu in another variable .
You should also correct the scope/braces of "if (menu == 'e')"
In current scenario if user selects option d , the control will come to first if, condition fails and it will not hit the check "if (menu == 'd')" as it is inside first if.
menu=getmenuselection(menu);
if (menu == 'e')
{
cout << "Enter original file name... ";
cin >> myname;
decryptkey (myname); // call to the function encrypt( )
cout << "Encrypted string is: " << myname <<endl;
return main();
}
That seems to have did the trick. Now I just got to figure out how to tell the program to handle more than 5 characters. Thanks for everyones help thus far. I am glad I joined, should've done this sooner.
So earlier in this thread My goal was to get the program to take a char user input and output it after it got transformed in either the encrypt function or decrypt function. Now I want to try to take this one step further and have the program obtain the user input from a txt. file. I have no errors when I run this code but it does not act like its supposed to. What gives?