My homework problem is to modify code written for a previous assignment that saved an array (of user-specified size) of test scores so that it also saves a parallel array of student names associated with these test scores. We are to use pointers and pointer notation whenever possible.
My problem occurs early on: I ask for the student's full name and receive the input using the getline cin object and cin.ignore() to avoid passing the last name into my next cout/cin request.
However, when I attempt to recall the student name using either pointer notation (deref the pointer) or array notation all I get is blank space. String objects have been the most difficult for me to grasp this quarter, so it is possible that it is just that I am missing a crucial bit of reasoning here. I have gone back and read through my text but it is not incredibly helpful as it shows my exact format for a similar desired result. Also, most online research has been yielding info that is well beyond a first quarter c++ student like myself. Any help is very much appreciated! Here is the snippet of code where I think my problem lies:
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
void sortArray(int*, string*, int);
void averageScore(int*, int);
int main()
{
//pointer to point to test scores
int* scores;
string* student;
// integer test to indicate size of array
int test;
// get user defined array size
cout << "How many tests would you like to save?" << endl;
cin >> test;
// define dynamically allocated array scores
scores = new int[test];
student = new string[test];
// for loop to enter each test score as an element of scores array
for (int i = 0; i < test; i++)
{
cout << "Enter the student's name: " << endl;
getline(cin, student[i]);
cin.ignore();
cout << "Enter the test score for " << *(student+i) << " : "<< endl;
cin >> *(scores+i);
EDIT:
I played around with it and was able to get the results I wanted with the following code:
for (int i = 0; i < test; i++)
{
cout << "Enter the student's first name: " << endl;
cin >> first;
cout << "Enter the student's last name: " <<endl;
cin >> last;
*(student+i) = first + " " + last;
cout << "Enter the test score for " << *(student+i) << " : "<< endl;
cin >> *(scores+i);