google-site-verification: googlebaca44933768a824.html Need help (again) - Old Royal Hack Forum

Announcement

Collapse
No announcement yet.

Need help (again)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Need help (again)

    Hello, im making siiimple C++ encryption / decryption program. here's the code:

    Code:
    #include <iostream >
    void encrypt( char [ ] );
    void decrypt( char * ePtr );
    int main( )
    {
        char vaihto [50];
        char vastaus;
        std::cout << "do you wanna crypt or decrypt?\n c/d" << std::endl;
        
        std::cin >> vastaus;
        if (vastaus == 'k')
        {
        std::cout << "write text you would like to encrypt" << std::endl;
        std::cin.get(vaihto, 49);
        std::cout << "you wrote: " << vaihto << std::endl;
        encrypt( vaihto );
        std::cout << "encrypted: " << vaihto << std::endl;
        system("pause");
        return 0;
        }
        else if (vastaus == 'd')
        {
            std::cout << "write the string you would like to decrypt" << std::endl;
            std::cin.get(vaihto, 49);
            decrypt( vaihto );
            std::cout << "Decrypted string is: " << vaihto << std::endl;
            system("pause");
            return 0;
        }
        else
            std::cout << "answer properly!" << std::endl;
            system("pause");
    }
    
    
    void encrypt (char e[] )
    {
    for( int i=0; e[i] != '\0'; ++i ) ++e[i];
    }
    
    void decrypt( char * ePtr ) {
    for( ; * ePtr != '\0'; ++ ePtr ) --(* ePtr);
    }
    now the decryption part works, but when I try to encrypt what ever, it will just skip the user input part. Why is that?
    ok bai

    #2
    Re: Need help (again)

    solved it, damn i was stupid...
    ok bai

    Comment


      #3
      Re: Need help (again)

      why was it? looked over it but couldn't get rid of errors i caused while fixing the other one Oo

      Comment


        #4
        Re: Need help (again)

        Imo C++ errors are always small details that you've forgotten :D

        Comment


          #5
          Re: Need help (again)

          Yah! Autocorrect would be usefull Oo

          Comment


            #6
            Re: Need help (again)

            Originally posted by xst View Post
            Yah! Autocorrect would be usefull Oo
            yes indeed :D.
            But if there is this ,it wouldnt be interrested its better to search the problem and undersatnd after ^^




            Comment


              #7
              Re: Need help (again)

              just needed to zero cin (cin.clear) before entering vaihto ;)
              ok bai

              Comment

              Working...
              X