Results 1 to 5 of 5
  1. #1
    Yotsuba's Avatar
    Join Date
    Sep 2012
    Gender
    male
    Location
    The Moon
    Posts
    1,391
    Reputation
    148
    Thanks
    732

    Need help with making a simple Hello World C++ Program

    So I just started my Computer Science class and I am having a lot of problems.

    I need to make a hello world program that can accept names and such.

    However, the program is I don't know how to do it so well. I can output Hello World, but I wanted to add names and answers. So in the end it would be like:

    Code:
    Hello, what is your name?
    (bob)
    Who is your friend?
    (suzy)
    This is Bob, he has a friend called Suzy. Bob kills Suzy.
    Can anyone help me out? I can't seem to find tutorials through Google
    hi

  2. #2
    InunoTaishou's Avatar
    Join Date
    Jan 2009
    Gender
    male
    Location
    The Internet
    Posts
    446
    Reputation
    20
    Thanks
    951
    My Mood
    Relaxed
    You'll need to include the header file string
    Code:
    #include <string>
    and create a couple of variables of type string to hold the user's input for Name and friend's name
    Code:
    string userName, friendName;
    then you'll be using the keyword cin to get user input

    If you've started a CS class then your first chapter should be on cout, cin, and should possibly include some basic data types (int, double float, and probably string).

    And since everyone is going to try to correct name and say it needs to be std::string, yes, I know that, and it should be, but this is a beginner computer science class. The teacher is going to have them doing
    Code:
    using namespace std;
    at the beginning of every project so it doesn't matter. When they get to some more intermediate programming the teacher will explain namespaces in more detail.
    And yes, you can use char* or char[] instead to hold the user input, but again, this is a beginner computer science class. Trying to explain a char* and char[] to people who don't even know what a function is is like trying to teach a cat dog tricks. It can be done, just not right now.
    Last edited by InunoTaishou; 02-08-2016 at 07:39 PM.
    https://www.mpgh.net/forum/signaturepics/sigpic210976_1.gif

  3. #3
    shanker33's Avatar
    Join Date
    Jan 2011
    Gender
    male
    Location
    Murica!
    Posts
    50
    Reputation
    10
    Thanks
    5
    I hope this helps.
    Code:
    #include <iostream> 
    #include <string>
    using namespace std;
    
    int main()
    {
    
        cout << "Hello, what is your name." << endl;          // endl; is one way of starting a new line
        string name;                                          // name is a string of chars
        cin >> name;                                          // user input 
    
        cout << "Who is your friend?" << endl;
        string Friend;
        cin >> Friend;
    
        cout << "This is " << name << ", he has a friend called " << Friend << ". " << name << " kills " << Friend << ".";
    
    }
    sorry if any errors but im sure you can figure it out.

  4. #4
    gogogokitty's Avatar
    Join Date
    Feb 2013
    Gender
    male
    Posts
    1,090
    Reputation
    113
    Thanks
    3,503
    simple way, it can be much neater but will do what you want. and can learn off of it easily.
    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
    	string friends;
    	string name;
    	cout << "Hello what is your name: ";
    		cin >> name;
    	cout << "And who is your friend: ";
    		cin >> friends;
    		cout << "This is " << name << ", and has a friend named " << friends << ". " << name << " kills " << friends <<endl;
    		system("pause");
    }
    LEEEEEEROY JEEEEENKINS

  5. #5
    Yemiez's Avatar
    Join Date
    Jun 2012
    Gender
    male
    Location
    Sweden
    Posts
    2,566
    Reputation
    731
    Thanks
    16,281
    My Mood
    Devilish
    Solutions have been posted.

    Solved

Similar Threads

  1. Hello everyone, need help with making an aimbot+wallhacker
    By rampage2gene in forum Point Blank Hacks
    Replies: 6
    Last Post: 04-24-2012, 06:35 PM
  2. [Help Request] Need help with making binds !
    By JonathanTBM in forum Vindictus Help
    Replies: 4
    Last Post: 05-10-2011, 07:40 PM
  3. I need help with making Cheat Engine not D/C
    By whtlight2 in forum Combat Arms Discussions
    Replies: 9
    Last Post: 10-13-2009, 10:23 PM
  4. need help with making somthing.
    By bobs__bees in forum Visual Basic Programming
    Replies: 1
    Last Post: 08-24-2009, 04:27 PM
  5. [Request]Need Help with making an UCE
    By Marsicano in forum Combat Arms Hacks & Cheats
    Replies: 0
    Last Post: 08-05-2008, 10:32 PM