hi. im having trouble storing values in arrays. i have to enter them in one by one but they dont seem to get stored when i have to use the values in other functions.
line 5 is for another function that is not shown here. for that function i have to find the largest, smallest, and how far apart the large and small one are but i cant do that if my values are being stored.
Since you're using a loop I believe you want to insert values in all of the elements of the arrays. In that case it is cin >> score[j], You are writing every value you input in the same position, the 18th (arrays start from 0), so the previous values are overwritten
I'm confused by cin >> setw(10). I didn't know you could use it for istreams
i have to have 17 values under each array. is there a way the values can go like that automatically when i type it in instead of be pressing the spacebar after each one.
i think setw(10) does not work with cin>>. you have to use it while you print arrays using cout<<.
moreover use itrator i in index of array while taking input.
1 2 3 4 5 6 7
void readthearrays (int score1[], int score2[], int score3[], int k) {
int j;
for (j = 0; j < k; j++) {
cin>> score1[j] >> score2[j]>> score3[j];
}
}
It's a typo. In loops 'i' is frequently used as index for arrays, but he meant "use j". Also it's not really an iterator, but an offset from the first element of the array
i think ill stick to pressing the space bars. i have a new problem now. i need to find the largest, smallest, and the range of the values. i think i have the correct function but maybe something is wrong in the main.
here is the function:
int findlargesmallrange (int numb[], int n, int &, int &, int &) {
int largestsofar = numb[0];
int smallestsofar= numb[0];
int howfarapart;
for (int j = 0; j < n; j++) {
if (largestsofar < numb[j]){
largestsofar = numb[j];
return largestsofar;
}
if (smallestsofar > numb[j]){
smallestsofar = numb[j];
return smallestsofar;
}
}
howfarapart = largestsofar - smallestsofar;
return howfarapart;
}
and here is the main:
1 2 3 4 5 6 7 8 9 10 11
int main()
{
int score1[SIZE], score2[SIZE], score3[SIZE], numb[SIZE], sumscores[SIZE];
int n = 17;
int largest, smallest, howfarapart;
findlargesmallrange(numb, 17, largest, smallest, howfarapart);
cout<< "largest is " << largest << endl;
cout<< "smallest is " << smallest << endl; //i have to run this part 4 times for each array and the new array.
cout<< "they are " << howfarapart;
cout<< " apart"<< endl << endl;