Problem in transferring information between function

#include <iostream>
using namespace std;

void welcome();

int main(int argc, char** argv)
{
char name[50], gender;
cout<<"Name: ";
cin.getline(name,50); //info name is collected
cout<<endl;
cout<<"Gender: ";
cin>>gender;
welcome();
return 0;
}

void welcome()
{
cout<<endl<<"Hi "<<name; //how can i transfer the info name collected in main() to this function?
cout<<" welcome to C++!";
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

constexpr size_t MaxNam {50};

void welcome(const char name[MaxNam]);

int main()
{
	char name[MaxNam] {}, gender {};

	std::cout << "Name: ";
	std::cin.getline(name, MaxNam); //info name is collected

	std::cout << "\nGender (M/F): ";
	std::cin >> gender;

	welcome(name);
}

void welcome(const char name[MaxNam])
{
	std::cout << "\nHi " << name << " welcome to C++!\n";
}

Topic archived. No new replies allowed.