I am trying to create a program where it will read in the student name, nationality, and grades, and calculate their tuition fee based on those information.

I began to write a bit of code by I have ran into some problems. When I try to run my code, the compiler says "warning C4700: local variable 'name' used without having been initialized" but continues to run the code. Then the program shuts down. What is happening?

In addition, on my fifth line I have "char *firstName;". I know that char* represents a pointer, but what does that mean and why can't I just use a string?

#include <iostream>
using namespace std;

struct Student {
	char *firstName;
	char *lastName;
	bool canadianship;
	int grades[10];
};

Student newStudent[10];

void addFirstName() {
	char *name;
	cout << "Student Name: ";
	cin >> name;
	newStudent[0].firstName = name;
}


int main() {
	addFirstName();
	cout << newStudent[0].firstName;	
	return 0;
}

can't I just use a string?

Yes you can :

#include <iostream>
#include <string>

using namespace std;

struct Student {
	string firstName;
	string lastName;
	bool canadianship;
	int grades[10];
};

Student newStudent[10];

void addFirstName() {
	string name;
	cout << "Student Name: ";
	cin >> name;
	newStudent[0].firstName = name;
}


int main() {
	addFirstName();
	cout << newStudent[0].firstName;	
	return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.