arrays

hi .. hope you will be fine and having good health as well.. would please sort something out for me,, I need your kind help..

Below is the code of a program,, it ask the user for information..

This is the output (Please, enter your first name: John
Hello, John!)


First Question:???
when I insert my full name JUNAID KHAN, so it just shows JUANID so can you please tell me why is this so and what th solution for that???

2ND Question:
how to write the same programme using functions?


#include<iostream>

using namespace std;
int main()
{
char question[]= "Please Enter your name : ? ";
char greeting[]= "Hello " ;
char yourname[200];


cout<< question;
cin>> yourname;
cout<< greeting << yourname;
return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
 
using namespace std;
 
char * GetPersonName( const char *question, char *name, size_t n )
{
    cout << question;

    cin.getline( name, n );  // answer to the 1st question
 
    return name;
}
 
void DisplayGreeting( const char *greeting, const char *person )
{
    cout << greeting << person << endl; 
}
 
int main()
{
    const size_t MAX_NAME = 200;
    const char question[]= "Please Enter your name : ? ";
    const char greeting[]= "Hello " ;
    char yourname[MAX_NAME];
 
    DisplayGreeting( greeting, GetPersonName( question, yourname, MAX_NAME ) );
 
    return 0;
}
 
Last edited on
closed account (jyU4izwU)
Answer One:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//Programed By John (lol or ibranext)
#include <iostream>
#include <conio>
using namespace std;

int main()
{
int fName,lName,greeting,end              ;//all my programs HAVE end it is Most important to me!
greeting=[Your greeting Here]             ;//Name It
cout << "\n Enter FIRST Name Here: " ;//Dont Touch Here
cin >> fName                                        ;//Dont Touch Here
cout << "\n Enter LAST Name Here: "  ;//Dont Touch Here
cin >> lName                                        ;//Dont Touch Here
clrscr()                                                  ;//Del it If You Dont Want It to Clear Screen.
cout << greeting << fName << lName ;//Dont Touch Here
cin >> end                                           ;//Dont Touch Here
}
Last edited on
How are your programs that "HAVE end it is Most important to me" related to the original post?! And what will occur if variable 'end' will not be important to author of the thread?!:)
Last edited on
@ibranext
1
2
cout << "\n Enter FIRST Name Here: " ;
cout << "\n Enter LAST Name Here: ";

What if some guy with the name "Gaius Julius Caesar" want to use this program? Actually people who have two part name is a minority. Most of the world does not have names consisting from two parts.
Topic archived. No new replies allowed.