0

Edited code to demonstrate new changes. Still need help passing the check 50

My code returns the initials of each name inputted, however I must have something off with the way I implemented it, since the following is consistently being thrown. (If I had to pinpoint the error, I'd say it has to do with taking the first name of the input outside of the loop.)

#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>

int main(void)
{   //prompt user for input, store input.
    printf("Please enter your name.");
    string s = GetString();

    //prints the first letter of their name in uppercase.
    printf("%c",toupper(s[0]));

    for(int i=0; i<strlen(s); i++)
    {

        if(s[i]==32)
        {
            printf("%c",toupper(s[i+1]));
         }


    }


}

The error it throws: :( outputs "MB" for "Milo Banana" \ expected output, but not "MB"

:( outputs "MB" for "milo banana" \ expected output, but not "MB"

:( outputs "RTB" for "Robert Thomas Bowden" \ expected output, but not "RTB"

:( outputs "R" for "ROB" \ expected output, but not "R"

:( outputs "RTB" for "Robert thomas Bowden" \ expected output, but not "RTB"

1 Answer 1

1

I really wish they'd clean up the ambiguity of this one. The problem is your prompt for the name. If you look at the instructions, it says early on "a program that prompts a user for their name". To me, that says to do what you did, but later, it gets more specific, saying that output should look exactly like the example that follows. The example does not include any prompt text, it should simply wait for input.

So, in my humble opinion, this isn't all your fault. Just remove the printf() call with the prompt. Of course, I haven't looked at the rest of the program for errors, so if you have them, well, that's another matter entirely. ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

5
  • I commented out the prompt for a name, however I'm still being thrown the following errors. :( outputs "MB" for "Milo Banana" \ expected output, but not "MB" :( outputs "MB" for "milo banana" \ expected output, but not "MB" :( outputs "RTB" for "Robert Thomas Bowden" \ expected output, but not "RTB" :( outputs "R" for "ROB" \ expected output, but not "R" :( outputs "RTB" for "Robert thomas Bowden" \ expected output, but not "RTB"
    – nmonte
    Commented Jul 20, 2016 at 13:39
  • :( outputs "RTB" for "Robert Thomas Bowden" \ expected output, but not "RT\nB\n" :( outputs "R" for "ROB" \ expected output, but not "R" :( outputs "RTB" for "Robert thomas Bowden" \ expected output, but not "RT\nB\n"This is what I get when I use check50 on your code: If you look closely at what has been output you will see there are extra characters between some of your initials. You need to understand why they are appearing as such and resolve. Commented Jul 22, 2016 at 14:31
  • I removed the \n from my printf line, however I'm still getting the same output errors :/
    – nmonte
    Commented Jul 22, 2016 at 14:44
  • It still needs a trailing line feed.
    – Cliff B
    Commented Jul 31, 2016 at 20:15
  • please elaborate, what is a trailing line feed?
    – nmonte
    Commented Aug 10, 2016 at 12:28

You must log in to answer this question.

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