How can I fix my compiling error on line 12?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kernmaster22
    New Member
    • May 2014
    • 1

    How can I fix my compiling error on line 12?

    Hi, I need help with my program. How can I fix my compiler error on line 12 of me code? It's not working for some reason. May I have feedback please?
    This is the problem:

    Your country is at war and your enemies are using a secret code to communicate
    with each other. You have managed to intercept a message that
    reads as follows:

    :mmZ\dxZmx]Zpgy

    Write a program that decrypts the intercepted message. You only know
    that the key used is a number between 1 and 100. Your program should
    try to decode the message using all possible keys between 1 and 100.
    When you try the valid key, the message will make sense. For all other
    keys, the message will appear as gibberish.

    Code:
    #include <iostream>
    #include <string>
    #include <vector>
    
    using namespace std;
    
    void input(char message[100], int& key);
    vector<char> encrypt(char message[100], int key);
    
    int main()
    {
        input(message[100], key);
        vector<char> encrypt(char message[100], key);
    
        return 0;
    }
    
    void input(char message[100], int& key)
    
    {
        cout << "Please enter an encrypted message: \n";
        cin.getline(message,100);
    }
    
    vector<char> encrypt(char message[100], int key)
    
    {
        int counter;
        char output[100];
    
        for(key = 1; key <= 100; key++)
        {
            for(counter = 0; message[counter]! = '\0' ; counter++)
            {
                if(message[counter] - key < 32)
                    output[counter] = message[counter] - key - 32 + 127;
                else
                    output[counter] = message[counter] - key;
            }
    
            cout << "Decrypted message using Key" << key << " : ";
            cout << output << endl;
        }
    
    }
    Last edited by Rabbit; May 5 '14, 12:19 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • divideby0
    New Member
    • May 2012
    • 131

    #2
    Code:
     input(message[100], key);
    the call here isn't right. you haven't declared any variables named input or key. declare a char array and an integer variable, and pass them as parameters to input.

    Code:
    char array[100] = { 0 };
    int key;
    
    input(array, key);
    Code:
    void input(char message[100], int& key)
    {
    cout << "Please enter an encrypted message: \n";
    cin.getline(message,100);
    }
    the function doesn't appear to change key in any way. are you supposed to alter its value?

    Comment

    Working...