Thread: Very small program...Whats wrong???

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    11

    Very small program...Whats wrong???

    #include <iostream>

    int main ()

    {

    char x;

    cout << "Hi, whats your name?";
    cin >> x;
    cout << "Your name is " << x ;

    return 0;

    }

    when i use this program this is what it will look like for example

    computer - Hi, whats your name?
    me - Brett
    Computer - Your name isbPress any key to continue
    Children in the dark make accidents.

    Accidents in the dark make children.

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    char holds a single character. You might want to look up character arrays (char*) or std::string
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    you also forgot to put in "using namespace std;" under "#include<iostream>"

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main ()
    
    {
    
    char x[20];
    
    cout << "Hi, whats your name?";
    cin.getline(x,20,'\n');
    cout << "Your name is " << x <<endl;
    
    return 0;
    
    }
    this works (i think)... it's what you're looking for... the last endl is just for formatting... not necessary...
    Last edited by major_small; 05-30-2003 at 08:59 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    11
    hey thanks man!
    Children in the dark make accidents.

    Accidents in the dark make children.

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    no problem... just make sure you know how it all works...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's wrong with my search program?
    By sherwi in forum C Programming
    Replies: 5
    Last Post: 04-28-2006, 09:57 AM
  2. Replies: 5
    Last Post: 01-31-2006, 01:54 AM
  3. Need help with small program to calculate a salary
    By Guti14 in forum C++ Programming
    Replies: 13
    Last Post: 01-11-2004, 05:54 PM
  4. Small program that has to calculate miles per gallon
    By Guti14 in forum C++ Programming
    Replies: 6
    Last Post: 01-06-2004, 02:47 PM
  5. How can I run a small ftp script from C program
    By bazeemuddin in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 07-01-2003, 05:04 PM