1

when I check my program, there is the "expected output, not a prompt for input" error for every input they are trying to check. however, when I am testing it, all inputs seem to be exactly the same as the output the check requires. Here is the code:

int main(int argc, string argv[])
{
    if (argc!=2)
    {
        printf("Please, enter one keyword.\n");
        return 1;
    }
    string Key = argv[1];
    int KeyLen = strlen(Key);
    for (int i=0; i<KeyLen;i++)
    {
        if (isalpha(Key[i]))
        {
            Key[i]=tolower(Key[i]);
        }
        else
        {
            printf("The key should not contain non-alphabetic characters.\n");
            return 1;
        }
    }
    string UserInput = GetString();
    int InputLen= strlen(UserInput);
    int KeyCount = 0;
    int j;
    for (j=0; j<InputLen; j++)
    {
        if (isalpha(UserInput[j]))
        {
            if(islower(UserInput[j]))
            {
                printf("%c", ((((UserInput[j]-97)+(Key[KeyCount]-97))%26)+97));
                if(KeyCount<KeyLen-1)
                {
                    if(KeyLen>1)
                    {
                        KeyCount++;
                    }
                }
                else
                {
                    KeyCount=0;
                }
            }
            if(isupper(UserInput[j]))
            {
                printf("%c", ((((UserInput[j]-65)+(Key[KeyCount]-97))%26)+65));
                if(KeyCount<KeyLen-1)
                {
                    if(KeyLen>1)
                    {
                        KeyCount++;
                    }
                }
                else
                {
                    KeyCount=0;
                }
            }
        }
        else
        {
            printf("%c", (UserInput[j]));
        }
    }
    printf("\n");
    return 0;
}

What am I doing wrong? Thank you in advance!!!

1 Answer 1

1

Current incarnation of the problem requires some additional output:

  • Otherwise, your program must proceed to prompt the user for a string of plaintext, p, (as by a prompt for plaintext:) which it must then encrypt according to Vigenère’s cipher with k, ultimately printing the result (prepended with ciphertext:) and exiting, with main returning 0.

(source)

5
  • I understand the problem lies somewhere around this specification implementation, however I do not see it. could you please be more specific? Commented Jan 24, 2017 at 10:12
  • 1
    Before GetString/get_string, print plaintext:, before printing the encrypted text, print ciphertext:
    – Blauelf
    Commented Jan 24, 2017 at 10:28
  • the staff's implementation does not have "plaintext:" or "ciphertext:" before the output, but I will try it, thank you! Commented Jan 24, 2017 at 13:19
  • Then the staff's implementation might require an update to the current rules. The error tells me the tests expect some kind of output before input, at least that's for sure.
    – Blauelf
    Commented Jan 24, 2017 at 14:51
  • The staff version does indeed have the printed prompts. Be sure to run update50 if you haven't done so. The IDE is version 94 at this point.
    – curiouskiwi
    Commented Jan 25, 2017 at 0:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .