invalid null pointer

I am new to C++ and am getting an invalid null pointer error message after a successful build. Can I get a hit where this is going wrong.
This program is supposed to ask for firstName, lastName, age and maJor and keep doing so until the age that is input is 0 and then the program closes. Here is what I have.

#include <iostream>
#include <string>


using namespace std;

void mydata ()
{
string firstName;
string secondName;
string maJor;
string myData;

cout<< secondName <<", " <<firstName <<", "<< "( " << maJor <<" )" <<endl<<endl;

}

int main ()
{

string firstName;
string secondName;
int age;
string maJor;
string myData =0;

cout<<" Please enter the persons first name, last name, age and major " <<endl;
cin>> firstName >> secondName>> age >> maJor;


myData = (firstName+secondName+ maJor);

if (age != 0)
{
cout<<(myData);
}
else cout<<"good job"<<endl;


return 0;

}
myData = (firstName+secondName+ maJor);


What are you trying to do here? This doesn't make sense. You can't set a function to a value, it's the other way around

And in your void myData(), cout<< secondName <<", " <<firstName <<", "<< "( " << maJor <<" )" <<endl<<endl;

Will do nothing because they are not assigned anything to print
@Phule99

Maybe this is more of what you had in mind..

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
31
32
33
34
35
36
37
38
39
40
41
// MyData.cpp : main project file.
#include <iostream>
#include <string>


using namespace std;

string mydata (string fName, string lName, string Major)
{
	string Data;
	Data = lName + ", "+fName+", ( "+Major+" )"; 

	return Data;

}

int main ()
{

	string firstName;
	string secondName;
	int age;
	string maJor;
	string Data ="";

	do
	{

		cout << "Please enter the persons first name, last name, age and major " <<endl;
		cin >> firstName >> secondName>> age >> maJor;
		if (age>0)
		{
			Data = mydata(firstName,secondName, maJor);
			cout << Data << endl << endl;
		}
	} while (age !=0);

	cout<<"Good job!! Thank you.."<<endl;

	return 0;
} 
Oh I see. Sorry, we are given handouts in class that tell us what we need to do but they don't tell us how to do it or why. I can understand, sort of, what needs to be done but not how to get there..

Thanks,
Topic archived. No new replies allowed.