Thread: 40 aplhastring

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    7

    Thumbs up 40 aplhastring

    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;}
    }
    Last edited by amits; 05-19-2004 at 04:41 AM.

  2. #2
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    Please, post your code, so we can see what is the problem

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    For starters, you're using C++ and not C. Next, why are you mixing your input types? You use both scanf and cin. That's usually considered a "no-no". Additionally, do you actually code like that? I can't imagine how. What with no indenting and all...

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Not returning correct results
    By drty2 in forum C Programming
    Replies: 4
    Last Post: 01-19-2009, 12:39 PM
  2. Fill Array char with 40 spaces.
    By sergioms in forum C Programming
    Replies: 8
    Last Post: 01-12-2009, 07:38 PM
  3. from perl to C
    By prettydainty in forum C Programming
    Replies: 5
    Last Post: 01-05-2009, 11:47 AM
  4. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  5. level up 6 times with 40 EXP!?!?!?!
    By Blizzarddog in forum Game Programming
    Replies: 15
    Last Post: 03-05-2003, 12:56 PM