Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how to ask the user their first name

+6 votes
asked Apr 16, 2025 by Ryan Farley (180 points)

1 Answer

+1 vote
answered Apr 16, 2025 by Peter Minarik (101,340 points)

What language are you after?

In C (and C++), you could do the following:

#include <stdio.h>

int main()
{
    char name[32];                                // We'll have a variable called "name" and can store up to 32 characters.
    printf("What's your name?\n");                // Asking the user for their name.
    printf(": ");                                 // Showing a prompt.
    scanf("%s", name);                            // Reading the name from the standard input.
    printf("Why, nice to meet you, %s!\n", name); // Using the "name" just to verify all went well.
    return 0;                                     // The program terminates indicating no error.
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...