0

Enter name: a
Enter GPA: 3
Enter major: 2

Name: a
GPA: 3
Major: 2


Name: a
GPA: 3
Major: 2


Enter name: b
Enter GPA: 3
Enter Major: 2

Name: b
GPA: 3
Major: 2


Enter name: c
Enter GPA: 3
please enter major: 2

Enter name: d
Enter GPA: 3
please enter major: 2
c 3 2
d 3 2


this is after change in call of printstudents into main

0

new code

#include <iostream>

using namespace std;


struct Student
{
	char Name[30];
	float GPA;
	int Major;
};

//Function prototypes
Student* StudentData(Student* S);
void display(Student* S);
void ChangeData(Student* S);
void GetStudents(Student array[], int size);
void PrintStudents(Student array[], int size);

//Main information build
int main()
{
	//Declare two objects of type 'Student' as wanted in step #1
	Student* S1 = new Student;
	Student* S2 = new Student;
	//Step #6
	Student Students[2];
	
	//Pass this object into the function so it can be filled up with useful information as wanted in step #2
	S1 = StudentData(S2);
	//Display new and exciting information as specified in step #3
	display(S1);
	display(S2);	
	//Function call to change data in S2 as specified in step #4
	ChangeData(S2);
	//Displays ChangeData
	display(S2);
	//Step #7
	GetStudents(Students, 2);	
    //Step #9
	PrintStudents(Students, 2);
	
	return 0;
}


//Function Definitions Which Ask For User Input And Displays Them
Student* StudentData(Student* S)
{
	cout << "Enter name: ";
	cin >> S->Name;
	
	cout << "Enter GPA: ";
	cin >> S->GPA;
	
	cout << "Enter major: " ;
	cin >> S->Major;
	
	return S;
}

void display(Student* S)
{
	cout << "                " << endl;
    cout << "Name: " << S->Name  << endl;
    cout << "GPA: " << S->GPA   << endl;
    cout << "Major: " << S->Major << endl;
	cout << "                " << endl;
}

void ChangeData(Student* S)
{
	cout << "\nEnter name: ";
	cin >> S->Name;
	
	cout << "Enter GPA: ";
	cin >> S->GPA;
	
	cout << "Enter Major: " ;
	cin >> S->Major;
}
void GetStudents(Student array[], int size)
{
		
	for(int i=0; i<size; i++)
	{
		cin.ignore(1);
		cout << "            " << endl;
		cout << "Enter name: ";
		cin.getline(array[i].Name, 30);
		
		cout << "Enter GPA: ";
		cin >> array[i].GPA;
		
		cout << "please enter major: " ;
		cin >> array[i].Major;
		
		
	}
}
void PrintStudents(Student array[], int size)
{
	for(int i=0; i<size; i++)
    {
		cout << array[i].Name << ' ' << array[i].GPA << ' ' << array[i].Major << endl;
    }
}
0

i called the function in line 18

You did not call the function in line#18, you simply declared the function prototype.

You called the function at line#41.

Edited by Clinton Portis: n/a

0

If it meets your project requirements and your compiler likes it, then it is declared right.

Also, try putting line #87 right before you call getline() at line #90.

Edited by Clinton Portis: n/a

0

is that it for number 9 after looking at it and reading i think it is

0

I don't know what you are talking about in your previous 3 posts. They seem to be random thoughts. Perhaps you are experiencing dementia associated with hours of coding in c++.

Edited by Clinton Portis: n/a

0

could be, but what i was trying to say is that the way i have it is the way you had it in the full code

0

You are a college student. This is not a proper and/or complete sentence:

it is isnt it getline is at 90 and the other is at 87

I will allow you one more opportunity to form a comprehensible question that resembles the English language.

Edited by Clinton Portis: am i asking too much here...

0

isnt getline on line 90 and on line 87 is where ignore has been put, you told me to put the ignore before getline will this work

}
void GetStudents(Student array[], int size)
{
		
	for(int i=0; i<size; i++)
	{
		cin.ignore(1);
		cout << "            " << endl;
		cout << "Enter name: ";
		cin.getline(array[i].Name, 30);
		
		cout << "Enter GPA: ";
		cin >> array[i].GPA;
		
		cout << "please enter major: " ;
		cin >> array[i].Major;
		
		
	}
0

Yes... I think that works as long as there are no cin >> operations that take place between the ignore() and the getline() operation.

I believe the cin operation will leave an extraneous newline character in the input buffer that will thwart the efforts of getline() to read the buffer.

It's 2:00am... what am I doing here...

Edited by Clinton Portis: n/a

2

Steps #1 through #9 are complete. Aside from the required error handling, the bulk of your project is complete.

Perhaps we could come up with a couple of functions to test user input for validity. If invalid, throw an error; catch error and respond appropriately.

But since I am tired as heck, I am about do like my programs and crash.

Votes + Comments
nuff said
You derserve rep for this monster thread.
0

thanks for your help ill be up until i can get this thing done we'll see how that goes

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.