When i print out the info the user inputs it gives me garbage.
when i print out the name it comes out blank and the grades are bunch of random numbers as well as the average.
Maybe I'm calling the functions wrong.
#include<iostream>
#include<string>
using namespace std;
//Abstract data type
struct Student
{
string name;
int id;
double grades[4];
};
//Declare variables
Student person;
double average;
Student* personPtr = &person;
//Program introduction
cout << "Hello. This program is design for you to input student information" << endl;
cout << "You will have to enter the student name, id and four test grades." << endl;
cout << "It will drop the lowest grade and give you th average of the remaining grades" << endl;
cout << "At the end of the program it will display all the information you inputed." << endl;
cout << "Lets begin." << endl;
//Calling functions
studentInfo(person);
cout << "------------------------------------" << endl;
average = getAverage(person);
printInfo(*personPtr, average);
cout << "------------------------------------" << endl;
You're passing person by value. Any changes made by that function are lost when that function exits because you're operating on a local copy of it. Not the caller's instance of it. You want to pass person by reference here so that the caller's instance of the struct is updated.