HELP Exiting a Function after an if statement!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • atiq
    New Member
    • Apr 2007
    • 36

    HELP Exiting a Function after an if statement!

    I want the function to exit (NOT continue) if the encryptedMess.t xt file does not exist!

    Below is the code for this function and it is after line 15 where i need help:


    Code:
    //Process of Decyption
    
    void Decrypt()
    {
    	char decrypted;
    	stringLoc =0;
    
    		char ch;
    
    
    		ifstream encryptedMess("encryptedMess.txt");		//Open Encrypted File message
    
    		if (!encryptedMess)
    		{
    			cout<<"Error opening the file"<<endl;
    			
    			
    		}
    		while (!encryptedMess.eof())
    		{
    			encryptedMess.get(ch);
    			decrypted = ch-difference;
    			
    			cout<<decrypted;
    		}
    		encryptedMess.close();
    		cout<<endl<<endl;
    
    //Save to text File
    		ofstream decryptedMess;
    		decryptedMess.open("decryptedMess.txt", ios::out);
    		decryptedMess<<decrypted;
    		decryptedMess.close();
    }

    Any help would be much appreciate!

    Thanks
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Look up the return statement in any basic book on the language (or on the web)

    Comment

    • atiq
      New Member
      • Apr 2007
      • 36

      #3
      Originally posted by Banfa
      Look up the return statement in any basic book on the language (or on the web)
      Thank you for your reply!

      i cant use a return statement because it is a void function. What alternative way can i achieve this? I would be grateful if you could provide the coding.

      Thanks

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Originally posted by atiq
        i cant use a return statement because it is a void function. What alternative way can i achieve this? I would be grateful if you could provide the coding.
        Yes you can, I repeat, look up the return statement in any basic book on the language.

        Comment

        Working...