We've been given the exercise below and I'm stumbling at the first block because we have to take in 20 student names and I don't know how to store them!
I know that I can create (initialize) 20 different char arrays but this seems wrong somehow...
What's the best way to store these string inputs?
Thanks, p.
Name Mark Grade
===== ===== =====
Sam 78 Distinction
Joe 54 Pass
���..
The attempts at a solution (include all code and scripts):
#include "stdafx.h"
#include <iostream>
#include <string.h>
using namespace std;
int main ()
{
char aName[15];
int aMark[15], iIndex;
char cName;
cout << "Enter Name and Mark: " << endl;
for (iIndex = 0; iIndex < 15; iIndex++)
{
cout << "Enter Name: ";
cin >> aName;
}
// test output
for (iIndex = 0; iIndex < 6; iIndex++)
{
cout << "Name Array output: " << aName[iIndex] << endl;
cout << "Mark Array output: " << aMark[iIndex] << endl;
}
return 0;
}
(obviously the above doesn't work...)
School (University) and Course Number:
Farnborough Tech - UK (C++ practitioners diploma)... Note this is NOT coursework it's just one of the examples we're given to work thru...