the PDF has the limitations and what im supposed to do for each option and the zip has the executable as to how is supposed to run and look.
my 1st problem is this do while loop that i enclosed put on */
im trying to keep the input running until i get a Y,y,n,N and when it receives any of those it goes into the if statements and quits the do while loop i dont understand why is it not working
im doing if choice not equal to y or Y or n or N show the message that you need to select y or N
if choice 2 happens to be y,Y,n,N i want it to quit and go to the right if statement
what im doing wrong for this part?
/*do{
035 cin>>choice2;
036 if(choice2!="y" || choice2!="Y" || choice2!="n" || choice2!="N")
037 {cout<<"please select Y or N";}
038
039 }while(choice2=="y" || choice2=="Y" || choice2=="n" || choice2=="N");
040 */ //my poor attempt at keeping the option repeating until user input y,Y,N,n
for my second part im having problem is working with arrays is confusing as hell
my idea for the second part is to have the user input
the # of shifts and i will substract by that amount
and shift letters respectivey
this is my idea for example i input the message hello,there!!!
it gets stored in message[140]; and now i want to shift my message by the # of shifts
my idea is to store the new message after is shifted into a new array but im confused about the syntax or how does that work i get all sorts of errors.
i want to do this
char newarray[140];
cin>>shift
for (int i=0;i<140;i++)
newarray=message[i]-shift; //new array would be a char to
the problems that i see here are the following how do i declare properly the newarray to save the value?
for this part is it newarray[]=message[i]-shift; or newarray[140]=message[i]-shift;??
some help on that would be extremely appreciated
thank you guys
#include <iostream>
using namespace std;
void intro(); //protoype
void intro()//function intro message describing what program does
{cout <<"COP2271 Encrypter/Decrypter\nThis program is supposed to decrypt and encrypt messages using\nthe Caesar Cipher algorithm.\n\n";
}
void menu()
{cout <<"Main Menu\n\n1. To input a message\n2. To encrypt a message\n3. To decrypt a message.\n4. To perform a statistical analysis of the message\nPress 0 to quit.\n\nPlease choose: ";
}
int main()
{ char loweralphabet[27]={"abcdefghijklmnopqrstuvwxyz"}; //array containing all the lowercase letters of the alphabet
char upperalphabet[27]={"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}; //array containing all the uppercase letters of the alphabet
int choice; //variable for menu to choose options
char choice2; // variable for option 1 if it wants to overwrite message
char message[140]; //array where message is to be stored and max is 140 characters as specified
char message2[140];
int shift;
int on=0;
intro();
do{
menu();
cin >> choice;
if(choice==1){
if(on==1){cout<<"Currently, your message is:\n";
int i=0;
for(i=0;message[i]!='\0';i++)
cout<<message[i];
cout<<endl<<"Are you sure you want to overwrite it? (Y/N)";
cin>>choice2;
/*do{
cin>>choice2;
if(choice2!="y" || choice2!="Y" || choice2!="n" || choice2!="N")
{cout<<"please select Y or N";}
}while(choice2=="y" || choice2=="Y" || choice2=="n" || choice2=="N");
*/ //my poor attempt at keeping the option repeating until user input y,Y,N,n
if (choice2=='y' || choice2=='Y')
{//on=0; past code put as reference
cout<<"Please give new message: ";
cin.get();
cin.getline(message,sizeof(message));
cout << endl;
} // turns on to 0 which makes it ask for message again
}
if(choice2=='n' || choice2=='N')
{cout<<"Going back to main menu\n"; // if user decides to not overwrite message display that
cout<< endl;}
if(on==0)
{cout << "Please give message: "; //ask user for message to be stored in array
cin.get();
cin.getline(message,sizeof(message)); //takes input from user and saves to message array
on=1;}
}
else if(choice==2){ //if statement if option 1 hasn't been run yet
if(on!=1)
cout<< "Please give a message first using option 1.\n\n";
else{ //if option 1 has run at least once then proceed to do shift
cout << "Please give the number of shifts to the left: ";
cin >> shift;
// get message array do + shift to the whole message by doing a for or a while loop
// then store this value into a new array that is a char if not values will be in ascii after summation
//
//display new messag inside the new array with shift
}
}
else if(choice==3)
{if(on!=1) //if statement if option 1 hasn't been run yet
cout<< "Please give a message first using option 1.\n\n";
// if option 1 has been run once proceed to decryp it
else{cout<<"test";
//grab array with shifted message and do opposite calculation to cancel it out
//store array back into another array
//cout array after modification
}
}
else if(choice==4)
{if(on!=1) //if statement if option 1 hasn't been run yet
cout<< "Please give a message first using option 1.\n\n";
// do option 4 nd proceed to test
else{cout<<"test";}
}
else if(choice==0)
{cout<<"Now quitting..";
cin.ignore();
cin.get();
}
else{cout<<"Wrong choice, please choose again.\n\n";
}
}while(choice!=0);
return 0;
}
Attached File(s)
-
pro3Spring2012.pdf (86.44K)
Number of downloads: 22 -
cipher(1).zip (12.69K)
Number of downloads: 13

New Topic/Question
Reply




MultiQuote





|