hi guys,
i am trying to do this program but can't compile it?
a) Prompt the user to input a string of characters up to a maximum of 40 characters
b) Read the string input from the keyboard
c) Output the sequence of characters in alphabetical order
d) Prompt the user to repeat the process if desired
is there anyone in whole earth who can do this?
okay.
there is only error:
unexpected end of file found.
here is the code:
#include <iostream>
#include <cctype>
#include <cstdlib>
int main()
{
char strspace[50]; /* enough ?? */
printf("Enter a string ");
scanf("%s",strspace);
printf("The string was >>%s<<\n",strspace);
using namespace std;
{ char ans;
do
{
//Declarations
char string[21];
char decrypt;
int i;
//Get string from user
cout<<"Enter a string no longer than 20 characters long:"<<endl;
cin.get(string,20);
cin.ignore(80,'\n');
cout<<endl;
//encrypt
for(int a = 0; a < strlen(string); a++)
{
if(isupper (string[a]))
i = (int) 'A';
else if(islower ((int) string[a]))
i = (int) 'a';
if(isalpha(string[a]))
{
string[a] = string[a] - i;
string[a] = string[a] + 1;
string[a] = string[a] % 26;
string[a] = string[a] + i;
}
}
//Ask for decrypt
cout<<"Would you like to decrypt this string? (y,n) ";
cin>>decrypt;
cout<<endl;
//Decrypt and output
if(decrypt != 'n') //decrypt?
{
for(int j = 0; j < strlen(string); j++) //decrypt individual characters
{
if(isalpha(string[j]))
{
if(isupper (string[j]))
i = (int) 'A';
else if(islower ((int) string[j]))
i = (int) 'a';
string[j] = string[j] - i;
string[j] = string[j] - 1;
if(string[j] < 0)
string[j] = 25;
string[j] = string[j] + i;
}
}
cout<<endl<<endl<<"The decrypted string is: "<<string<<endl<<endl;
}
//Run again code
cout<< "Would you like to run this program again? (y,n) ";
cin>>ans;
cin.sync();
}while(ans != 'n');
return 0;}
}