Thread: how to stop the loop

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    7

    Thumbs up how to stop the loop

    i have done this porgram that sorts alphabets in ascending or descending order,
    when compiling this program, i only get one error saying

    fatal error c1004 : unexpected end of file found.

    here is the code:



    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;}
    }



    can anyone investigate what the error is?

    thanks
    Last edited by amits; 05-19-2004 at 06:15 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can a "switch" be inside a loop?
    By gmk0351 in forum C Programming
    Replies: 5
    Last Post: 03-28-2008, 05:47 PM
  2. need help, fgets won't stop while loop
    By Enkid in forum C Programming
    Replies: 6
    Last Post: 10-26-2007, 07:15 AM
  3. return to start coding?
    By talnoy in forum C++ Programming
    Replies: 1
    Last Post: 01-26-2006, 03:48 AM
  4. How to change recursive loop to non recursive loop
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 06-24-2002, 08:15 AM
  5. 2 largest elements; -1 to stop loop
    By Peachy in forum C Programming
    Replies: 4
    Last Post: 09-16-2001, 05:16 AM