Use a struct. Use loops. But don't use a look loop for (int i=0; i < 1; i++) because, honestly, what's the point?
e.g.
#include <iostream>
using namespace std;
const int RUNNER_DAYS = 7;
struct Runner {
const char *name;
int milesDay[RUNNER_DAYS];
};
void showRunner(Runner &item) {
cout << item.name << endl;
cout << " ";
for(int i=0; i<RUNNER_DAYS; i++) {
cout << ' ' << item.milesDay[i];
}
cout << endl;
}
int main() {
const int runnersCount = 5;
Runner runners[runnersCount] = {
{ "jason", {1,2,3,4,5,6,7} },
{ "samantha", {2,4,6,8,10,12,14} },
{ "ravi", {3,6,9,12,15,18,21} },
{ "sheila", {1,1,4,4,7,8,10} },
{ "ankit", {5,5,5,5,5,5,5} },
};
for (int i=0; i<runnersCount; i++) {
showRunner(runners[i]);
}
return 0;
}

New Topic/Question
Reply





MultiQuote





|