Sunday, August 2, 2009

Need help with a c++ program please?

Need help with a C++ program?


Hey guys I have a program that I need to write and I have no idea how to do it:


this program has to prompt the user in a menu to encrypt a message, decrypt or quit.


I'm supposed to use functions in this program


This is what i am supposed to use without removing any parts, just adding things where needed.


#include%26lt;iostream%26gt;


using namespace std;





int menu();


void encrypt(int);


void decrypt();








int main(){





int choice;


int shift = 7; // default shift


choice = menu();


while (choice != 3){


if (choice == 1){


cout %26lt;%26lt; "Enter the 'shift' value: ";


cin %26gt;%26gt; shift;


encrypt(shift); }


else


decrypt();





cout%26lt;%26lt;endl%26lt;%26lt;endl%26lt;%26lt;endl;


choice = menu();


}


return 0;


}


I don't even know how to get started functions kind of confuse me


Can someone at least point me in the right direction?

Need help with a c++ program please?
I'll work on this a bit... don't know what Ill have time for...





int menu(){


int choice=0;





while (choice%26lt;1 || choice%26gt;3){


cout%26lt;%26lt;"Enter 1 for encrypt, 2 for decrypt, 3 to quit -%26gt; ";


cin%26gt;%26gt;choice;


}


return choice;


}





For the encrypt and decrypt functions I presume you will need to pass an array of characters (a string) to manipulate.
Reply:eh functions are easy.


They take things in and return things.





This is what the function does:


Return Function(Input);





void mean it doesn't either take something or return something.








//Function Declaration


int Function(int)





//Example of a function in use


int a = Function(8)


//a = 9 at this point





//The function


int Function(int var)


{


int Var = var; //Var = 8


Var += 1; //or Var++, or Var = Var+1; //Var = 9


return Var; //Var = 9


}





It get's more complicated when passing a whole string "This is a test", or an array of numbers. There you pass by reference or by using pointers.


No comments:

Post a Comment