String | A Site Welcome Message

Wednesday, 2 January 2013


We are all familiar with networking sites, emails and other sites that gives us entertainment over the internet. Before we can access these sites we need to register first to become one of their members and access lots of features you might really like. One thing we observe after registration process is the welcome message we see on the screen bearing our names, like this, "Welcome Reymond Ayala". These welcome notes only mean one thing, we are successfully registered.

I thought of making a program that will look like that welcome note on sites. This program is used with a string command that will basically read all your character inputs. Check out the codes below.


   1:  #include <iostream>
   2:  #include <conio.h>
   3:  #include <string>
   4:   
   5:   
   6:   
   7:  int main()
   8:  {
   9:      std :: string firstName = "";
  10:      std :: string lastName = "";
  11:      std :: cout << "Enter your first name and press Enter: ";
  12:      std :: cin >> firstName;
  13:      std :: cout << std::endl;
  14:      std :: cout << "Enter your last name and press Enter: ";
  15:      std :: cin >> lastName;
  16:      std :: cout << std::endl;
  17:      std :: cout << "Hello, " << firstName << " "<< lastName << std::endl << std::endl;
  18:      getch();
  19:  }



When run, this program will ask you to input your first name and last name then all of your inputs will be stored in the firstName and lastName memory storage. After entering your first and last name it will then go to the last cout statement and show you the message Hello,"name" on the screen. Then you can now terminate the program. Check out the sample output below.



Hope you learned something. Feel free to leave a comment below. Thanks!

No comments:

Post a Comment

Please do leave a comment. It's gonna be a friendly conversation between programmers. Hope you do find our blog helpful. Thank you!

Related Posts Plugin for WordPress, Blogger...