Click here to Skip to main content
15,924,193 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi im having trouble with a cypher program which asks the user to input a shift number then that number shifts an alphabet array so it is encrypted please help
p.s i cant use headers

C++
#include <iostream>

using namespace std;


int getlength(char[]);
char makecypher(int);

int main(void) {

	 int shift;
	int length = 0;
	char inputarray[256];
	char array[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't','u', 'v', 'w', 'x','y', 'z' } ;



	cout << " Please input a string: ";
	cin.getline ( inputarray,256);

	// for loop to get lower case chars
	for(int i = 0; inputarray[i] != 0; i++)
	{
		if(inputarray[i] >= 'A' && inputarray[i] <= 'Z')
		{
			inputarray[i] += 32;
		}

		length++;
	}

	// removes spaces and non alphabetic chars
	for(int j = 0; inputarray[j] != 0;	 j++)
	{
		if ((inputarray[j] < 97) || (inputarray[j] > 122))
		{
			int remove = 1;
			for(int k = 0; k < length; k++)
			{
				inputarray[j+k] = inputarray[j+remove];
				remove++;
			}

			j--;
		}
		
	}
		
	



	cout << "You input: \n" << inputarray <<"\n";
	cout << " The length of the string is:  " << getlength(inputarray);
	cout << "\n";
	cout << " please enter the shift value:  ";
	cin  >> shift;
	cout << " the alpha :   " << makecypher(shift);



	

     

	cin.ignore(3);
}


int getlength(char inputarray[])
{
	int charlength = 0;

while((*inputarray) != '\0')

{
	 charlength++;
	 inputarray++;
}


return charlength;
	
}



char makecypher( int shift )

{
	char alphaarray[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 
               'n', 'o', 'p', 'q', 'r', 's', 't','u', 'v', 'w', 'x','y', 'z' } ;
	char cipherarray[27];

int i = 0;
static int shift;

for (int z = 0; z < 26; z++) // For Loop to adjust shift value
{
      // If statement condition to check whether the shift value is less than 26
      if (z < 26)
      {
      // Then shift and replace the element in the array
      cipherarray[z] = alphaarray[shift];

     i++; // Increment i to get the next character in the array
     }
}	

}

void encrypt ()

{
}
Posted
Updated 11-Dec-12 13:48pm
v2

1 solution

static int shift;


redefinition of formal parameter 'shift'.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900