I don't understand what I am doing wrong:

I'm developing a program for a school project and it's just not working. I need to get a player's age, and a player's nine scores (which I have), then I have to find what age group they are in (which I know), then I have to compare their scores to the scores that are predetermined for their age group which are stored in a constant 2D Array. Then I have to print if they were "Over", "Under", or "Par" an EACH hole number. The age groups are the rows and the holes are the columns in this constant array. See what I have and PLEASE tell me what is going on in the most basic C++ you know. I'm about ready to pull my hair out!

#include<iostream>
using namespace std;


int main() {
const int PAR[5][9] = {{8, 8, 9, 7, 5, 7, 8, 5, 8},
{7, 7, 8, 6, 5, 6, 7, 5, 6},
{6, 5, 6, 5, 4, 5, 5, 4, 5},
{5, 4, 4, 4, 3, 4, 3, 3, 4},
{4, 3, 3, 3, 2, 3, 2, 3, 3}};
int scores[9] = {5, 6, 4, 3, 2, 1, 8, 6, 4};
int i;
int hole = 0;
int age = 8;
int row;
int x;
int AGE_GROUP[5] = {1, 2, 3, 4, 5};
int AGE_RANGE[5] = {0, 5, 8, 12, 16};


for ( i = 0; i < 9; i++) {
cout << "Enter a score: ";
}


for (i = 0; i < 9; i++) {
cout << scores << " ";
}
cout << endl;
x = 5 - 1;
while (age < AGE_RANGE[x]) {
x = x - 1;
}
cout << age << " is in group number " << AGE_GROUP[x] << endl;
AGE_GROUP[age] = row;


while (hole < 9) {


if (scores[hole]> PAR[row][hole]) {
cout << "Over";
}
else if (scores[hole] == PAR[row][hole]) {
cout << "Par";
}
else if (scores[hole] < PAR[row][hole]){
cout << "Under";
}
hole++;
}
cout << endl;
system("PAUSE");
return 0;
}

Edited 3 Years Ago by happygeek: fixed formatting

I think your problem lies here: AGE_GROUP[age] = row; .

Maybe you wanted to write row = AGE_GROUP[AGE]; .

Also,

for ( i = 0; i < 9; i++) {
     cout << "Enter a score: ";
}

for (i = 0; i < 9; i++) {
     cout << scores[i] << " ";
}

is weird. Why make two loops? And how is the user supposed to insert something if you don't let him/her do it?

EDIT: One really minor issue, regarding nice-looking output only: I think you'd be better putting the endl; inside your while loop :)

And please, use code tags ^^"

No need to be sorry, we all learn from our mistakes :)

However, it wasn't the loop your problem, but the wrong assignment to row.

I tried it, program blew up! anything else? right now it works for that specific age, but all the other ones it doesn't! Help!

Try row = AGE_GROUP[x] instead of row = AGE_GROUP[age] . The second will force your program to have a nice trip out ot the array limits if you enter any age >=5.

Sorry to tell you this now, at a first glance I didn't noticed it :P

OH THANK YOU GOD IN HEAVEN!!!!!!!! I am such an idiot, I've been messin' with it ALL DAY!!! And it was the stupidest thing!!!!
Thank you so much!

This article has been dead for over six months. Start a new discussion instead.