Question: I'm trying to write a code in C++ that prompts the user to enter their name, age, and major, saves it as members of a

I'm trying to write a code in C++ that prompts the user to enter their name, age, and major, saves it as members of a struct, and then outputs the data to screen by calling a void function. However, the function only prints the first 4 characters of the array that is storing the name. Can someone help?

#include

using namespace std;

struct PersonInfo{

char name[50]; int age; string major; };

void print( char Name[], int old, string field); int main() { PersonInfo person1; cout<<"Enter your name: "<>person1.age; cout<<"Enter your major: "; cin>>person1.major;

print(person1.name,person1.age,person1.major);

return 0; }

void print (char Name[], int old, string field) { cout<<"Student Name: "; for(int index = 0;index

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!