Feb 8, 2014 at 3:25am UTC
I have an array of strings and a two dimensional array made up of floats.
In the output for the strings (this array stores 10 divers numbers) I am getting only 8 of the numbers, then a core dump. What could cause this?
Feb 8, 2014 at 3:29am UTC
Any number of things.
Present a minimal snippet of code that reproduces the problem and someone can probably tell you what, specifically, that may be.
On the other hand "I have code and it doesn't work" doesn't give anyone a whole lot to work with.
Feb 8, 2014 at 3:30am UTC
It has two nested loops, do you want the whole function for the inputs?
Feb 8, 2014 at 3:38am UTC
These are being read from a file:
for (int d=0 ; d<divers(10) ; d++)
{
float total=0;
input>>diver[d];
======the input for diver[] is string====
for(int i=0 ; i<difficulty(5) ; i++)
{
sum=0;
input>>difficulty[i];
for(int s=0; s<divers(also 5) ; s++)
{
input>>judge;
sum+=judge;
===In here, I'm finding min and max====
}
Feb 8, 2014 at 3:42am UTC
@br26354
You could check the function and make sure you are not assigning or reading, outside the array boundaries. To me, it sounds like you are. The array would go from 0 to 9, for a 10 element array.
Feb 8, 2014 at 3:45am UTC
I have a constant set at ten for the diver numbers.
Feb 8, 2014 at 3:47am UTC
Well, to get around this, I changed the datatype to int. I get ten values, but all but the last three are really big numbers.
Last edited on Feb 8, 2014 at 3:48am UTC
Feb 8, 2014 at 4:06am UTC
The code you are presenting here doesn't compile, therefore it isn't sufficient to reproduce your problem, unless your problem is that the code doesn't compile.
Feb 8, 2014 at 4:12am UTC
I am using a program called putty. Is there a way to copy and paste the text onto this page?
Feb 8, 2014 at 4:24am UTC
dispResult(diverNumbers,indScores,numofDivers, diveScore, average );
return 0;
}
void readScores(int diver[],float difficulty[], float score[][diveScore+1], int\
divers, int diff, int scores)
{
ifstream input;
float sum=0;
float smallest=FLT_MAX;
float biggest=0;
float calcScore;
float BigSmallDiff;
float judge;
input.open("divers.dat");
if(input.fail())
{
cout<<"File failed to open!";
exit(0);
}
for (int d=0 ; d<divers ; d++)
{
float total = 0;
input>>diver[d];
for (int i=0 ; i<diff ; i++)
{
sum=0;
input>>difficulty[i];
for (int s=0 ; s<scores ; s++)
{
input>>judge;
sum+=judge;
if(judge<smallest)
smallest=judge;
if(judge>biggest)
biggest=judge;
}
score[d][i]=((sum-(biggest+smallest))*difficulty[i]);
total += ((sum-(biggest+smallest))*difficulty[i]);
}
score[d][5]=total;
}
input.close()
}
Feb 8, 2014 at 4:40am UTC
123
3.5
5.5 6.0 7.0 6.5 6.5
3.2
5.5 6.5 6.0 5.5 7.5
4.2
4.5 4.5 5.0 5.5 5.0
4.5
5.5 5.5 6.5 7.0 6.5
4.0
7.0 8.0 7.0 9.0 8.5
987
2.9
2.0 8.0 8.5 8.5 9.0
2.5
8.0 8.5 8.0 8.0 9.0
3.2
7.5 7.5 6.5 5.0 5.5
4.0
5.0 4.0 4.5 5.0 5.5
4.2
4.5 5.5 6.5 6.5 5.5
293
2.1
7.5 8.5 8.0 9.0 8.5
3.0
7.0 7.5 8.0 8.5 8.0
4.2
8.5 7.5 7.5 6.5 6.0
4.5
2.5 2.5 3.0 3.5 4.0
4.8
7.5 8.0 8.0 9.0 8.5
567
3.1
8.0 9.0 9.5 10.0 9.9
4.4
8.9 9.5 9.5 9.0 8.0
4.5
10.0 9.0 10.0 9.5 8.0
4.8
9.0 9.0 9.0 9.0 9.0
4.8
8.5 7.5 7.5 7.0 6.5
883
2.4
8.5 8.5 8.5 8.5 8.5
3.2
8.5 6.5 7.5 7.0 6.5
4.2
7.5 8.0 9.0 8.0 8.0
4.5
8.0 8.0 7.0 6.5 7.5
4.4
9.0 9.5 8.5 10.0 9.0
461
4.8
8.5 9.0 9.5 9.5 9.5
4.5
9.5 9.0 8.5 7.0 9.5
4.0
8.5 8.5 8.5 9.0 10.0
4.5
9.5 8.5 9.0 9.0 9.5
4.3
10.0 10.0 10.0 10.0 10.0
276
3.5
8.0 7.5 7.5 6.0 8.5
3.6
7.5 8.5 8.5 8.5 7.5
3.8
8.0 6.5 6.5 6.0 7.0
3.2
8.0 8.0 8.0 8.0 8.0
4.0
9.0 8.0 9.0 8.5 8.5
789
2.2
9.0 9.2 9.3 8.9 8.7
2.4
8.5 8.8 7.5 8.0 8.0
3.2
7.5 7.5 6.5 7.0 8.0
3.5
8.0 7.5 7.0 6.5 6.5
4.1
7.5 7.5 7.0 7.0 6.5
422
3.2
10.0 10.0 10.0 10.0 10.0
3.4
9.0 8.5 8.0 10.0 10.0
3.5
8.0 8.5 8.0 7.5 7.5
3.4
5.5 5.5 6.0 6.0 6.5
4.0
7.5 7.5 8.0 8.0 9.0
612
4.2
7.5 7.0 7.5 7.0 9.0
3.6
8.5 8.0 8.5 7.5 8.5
4.1
8.5 9.0 9.0 8.5 8.0
3.8
8.0 7.5 7.5 7.5 8.0
4.0
6.5 6.5 5.5 5.0 7.0
this is what's being read in. the files is called divers.dat
Feb 8, 2014 at 4:49am UTC
You say divers equals 10, and I assume the integers represent diver numbers. But the data doesn't match 5 difficulties and 5 scores, you have 30 floats, what are the other 20?
Feb 8, 2014 at 5:05am UTC
They are integers, but they were originally string.
There are 5 sets of five scores, and each set of scores is preceeded by a difficulty score.
I'm doing the math to get each set of scores and difficulties into a set of ten totals.
five sets of five=25 + five diff scores=30.
They should all be there.
Feb 8, 2014 at 5:54am UTC
Ah I see, It is difficult to see the loops in unformatted code (use code tags).
This is suspicious score[d][5]=total;
Feb 8, 2014 at 10:04am UTC
d[i]column[5]=total.
I'm assigning the fifth column the totals.