Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

HELP!

novasheepnovasheep Member Posts: 29
Hello im very new to programming and im just doing a simple code here for a person to enter a user name well it works and all but all it displays is the first letter of the name. How do I fix this? And im sorry that my stupid ness is lowering the IQ of you viewers. But your help is very much appreciated.


#include

char UserName;

main (void)

{
std::cout << "Enter User Name: ";
std::cin >> UserName;



std::cout << "Hello: " << UserName << std::endl;

return 0;
}

Comments

  • shobhashobha Member Posts: 5
    you have declared
    "UserName" as "Char" Hence it is printing the first letter of the name.
    Change UserName to a string i.e char UserName[10];






    : Hello im very new to programming and im just doing a simple code here for a person to enter a user name well it works and all but all it displays is the first letter of the name. How do I fix this? And im sorry that my stupid ness is lowering the IQ of you viewers. But your help is very much appreciated.
    :
    :
    : #include
    :
    : char UserName;
    :
    : main (void)
    :
    : {
    : std::cout << "Enter User Name: ";
    : std::cin >> UserName;
    :
    :
    :
    : std::cout << "Hello: " << UserName << std::endl;
    :
    : return 0;
    : }
    :

  • PeterTheMasterPeterTheMaster Member Posts: 636

    thats what it has to look like. a char is only one single character (e.g. a letter), whereas string can store entire words or sentences.
    if you want the user to input his first and last name (anything that contains spaces), do what the comment says. in case u use vc++6 you have to update the string header for getline to work.

    : [code]
    : #include
    : #include
    :
    : int main()
    :
    : {
    : std::cout << "Enter User Name: ";
    : std::string UserName;
    : std::cin >> UserName; //replace by std::getline(std::cin, UserName);
    :
    :
    :
    : std::cout << "Hello: " << UserName << std::endl;
    :
    : return 0;
    : }
    : [/code]

  • Shawn CarterShawn Carter Member Posts: 0

    _______ | http://forcoder.org | free ebooks and video tutorials about | Swift, PL/SQL, Perl, Go, Ruby, Visual Basic .NET, Visual Basic, Delphi, JavaScript, Scratch, C#, Java, Objective-C, Assembly, MATLAB, C, PHP, C++, R, Python Kotlin, Dart, SAS, Lisp, COBOL, Awk, Scheme, Lua, Clojure, Prolog, Transact-SQL, FoxPro, VBScript, F#, LabVIEW, D, Erlang, Scala, ML, Rust, ABAP, Hack, Bash, Logo, Fortran, Alice, Ada, Crystal, Julia, Apex | _____

Sign In or Register to comment.