Sirena400

Mar 14, 2005, 11:43 AM

I thought at first that my code was okay but then when I actually tried running it I got an illegal vector index: 6 max index = 5 as a message. :confused: I've tried fixing it but I can't seem to find the problem. Can any of you guys figure out where I went wrong? Here's the code, and please excuse the poor programming, I'm not very good ^^;

#include <iostream.h>

#include <math.h>

#include "apvector.h"

apvector<double>scores(6);

apvector<double>darts(6);

int main()

{

double distance=0;

double location=0;

double total=0;

double final=0;

double q=0;

double p=0;

for (int x=0;x<scores.length();x++)

{

cin>>scores[x];

}

for (int y=0;y<darts.length();y++)

{

cin>>darts[x];

}

for (x=0;x<scores.length();x+=2)

{

if (scores[x]>0 && scores[x+1]>0)

q=4;

else if (scores[x]<0 && scores[x+1]>0)

q=3;

else if (scores[x]<0 && scores[x+1]<0)

q=2;

else (scores[x]>0 && scores[x+1]<0);

q=1;

}

for (y=0;y<darts.length();y+=2)

{

if (darts[y]>0 && darts[y+1]>0)

p=4;

else if (darts[y]<0 && darts[y+1]>0)

p=3;

else if (darts[y]<0 && scores[y+1]<0)

p=2;

else (darts[y]>0 && darts[y+1]<0);

p=1;

}

distance=sqrt((scores[x]*scores[x])+(scores[x+1]*scores[x+1]));

location=sqrt((darts[y]*darts[y])+(darts[y+1]*darts[y+1]));

if (distance<=7)

{

total=total+10;

}

else if (distance<=15 && distance>7)

{

total=total+7;

}

else if (distance<=55 && distance>15)

{

total=total+q;

}

else if (distance<=59 && distance>55)

{

total=total+(q*3);

}

else if (distance<=85 && distance>59)

{

total=total+q;

}

else if (distance<=89 && distance>85)

{

total=total+(q*2);

}

else (distance>89);

{

total=total+0;

}

if (location<=7)

{

final=final+10;

}

else if (location<=15 && location>7)

{

final=final+7;

}

else if (location<=55 && distance>15)

{

final=final+p;

}

else if (location<=59 && distance>55)

{

final=final+(p*3);

}

else if (location<=85 && location>59)

{

final=final+q;

}

else if (location<=89 && location>85)

{

final=final+(q*2);

}

else (location>89);

{

final=final+0;

}

if (total>final)

{

cout<<"First player wins, "<<total<<"-"<<final<<".";

}

if (final>total)

{

cout<<"Second player wins, "<<final<<"-"<<total<<".";

}

if (final=total)

{

cout<<"Tie game. "<<final<<"-"<<total<<".";

}

return 0;

}

#include <iostream.h>

#include <math.h>

#include "apvector.h"

apvector<double>scores(6);

apvector<double>darts(6);

int main()

{

double distance=0;

double location=0;

double total=0;

double final=0;

double q=0;

double p=0;

for (int x=0;x<scores.length();x++)

{

cin>>scores[x];

}

for (int y=0;y<darts.length();y++)

{

cin>>darts[x];

}

for (x=0;x<scores.length();x+=2)

{

if (scores[x]>0 && scores[x+1]>0)

q=4;

else if (scores[x]<0 && scores[x+1]>0)

q=3;

else if (scores[x]<0 && scores[x+1]<0)

q=2;

else (scores[x]>0 && scores[x+1]<0);

q=1;

}

for (y=0;y<darts.length();y+=2)

{

if (darts[y]>0 && darts[y+1]>0)

p=4;

else if (darts[y]<0 && darts[y+1]>0)

p=3;

else if (darts[y]<0 && scores[y+1]<0)

p=2;

else (darts[y]>0 && darts[y+1]<0);

p=1;

}

distance=sqrt((scores[x]*scores[x])+(scores[x+1]*scores[x+1]));

location=sqrt((darts[y]*darts[y])+(darts[y+1]*darts[y+1]));

if (distance<=7)

{

total=total+10;

}

else if (distance<=15 && distance>7)

{

total=total+7;

}

else if (distance<=55 && distance>15)

{

total=total+q;

}

else if (distance<=59 && distance>55)

{

total=total+(q*3);

}

else if (distance<=85 && distance>59)

{

total=total+q;

}

else if (distance<=89 && distance>85)

{

total=total+(q*2);

}

else (distance>89);

{

total=total+0;

}

if (location<=7)

{

final=final+10;

}

else if (location<=15 && location>7)

{

final=final+7;

}

else if (location<=55 && distance>15)

{

final=final+p;

}

else if (location<=59 && distance>55)

{

final=final+(p*3);

}

else if (location<=85 && location>59)

{

final=final+q;

}

else if (location<=89 && location>85)

{

final=final+(q*2);

}

else (location>89);

{

final=final+0;

}

if (total>final)

{

cout<<"First player wins, "<<total<<"-"<<final<<".";

}

if (final>total)

{

cout<<"Second player wins, "<<final<<"-"<<total<<".";

}

if (final=total)

{

cout<<"Tie game. "<<final<<"-"<<total<<".";

}

return 0;

}