# how do you

find and output the largest index value of a partucular array?
do i need to list them all in a greater than sort of "if"?
Michele

• : find and output the largest index value of a partucular array?
: do i need to list them all in a greater than sort of "if"?
: Michele
:

Loop through the array and use another variable to keep track of the largest value.
• : :
I'm trying like this:
[code}

for (x=0; x < SIZE; x++){
infile >> arr[x];
largest = arr[x];
for (int z=1; z,20; z++)
if(arr[z]>largest)
largest = arr[z];

outfile<<setw(40) << x <<setw(6)<< arr[z] << endl;}

}

[/code]
and getting an error that largest is an undeclared identifier.
Hey stober, thanks for the help. Much appreciated
M

find and output the largest index value of a partucular array?
: : do i need to list them all in a greater than sort of "if"?
: : Michele
: :
:
: Loop through the array and use another variable to keep track of the largest value.
:

• : : :
meant z<20
still getting the same error

: I'm trying like this:
: [code}
:
: for (x=0; x < SIZE; x++){
: infile >> arr[x];
: largest = arr[x];
: for (int z=1; z,20; z++)
: if(arr[z]>largest)
: largest = arr[z];
:
:
: outfile<<setw(40) << x <<setw(6)<< arr[z] << endl;}
:
: }
:
: [/code]
: and getting an error that largest is an undeclared identifier.
: Hey stober, thanks for the help. Much appreciated
: M
:
: find and output the largest index value of a partucular array?
: : : do i need to list them all in a greater than sort of "if"?
: : : Michele
: : :
: :
: : Loop through the array and use another variable to keep track of the largest value.
: :
:
:

• [b][red]This message was edited by scuba22 at 2002-10-27 17:55:43[/red][/b][hr]
: : : :
i am getting the largest index value with L (below) but the Location coming out is 3 and it should be 14...do you see a bug?
Mish
[code]
int L=0;
for (x=0; x < SIZE; x++)
infile >> arr[x];
L = arr[0];
for (int z=1; zL)
L = arr[z];
outfile<<setw(40) << arr[z] <<setw(6)<< L << endl;

[/code]
• You're close
[code]
int foo(int arr[])
{
int L = -10000;
for (int x=0; x < SIZE; x++)
{
infile >> arr[x];
if(arr[x] > L)
L = arr[x];
outfile<<setw(40) << arr[z] <<setw(6)<< L << endl;
}
return 0;
}
[/code]

• :
i'm not following you - in your code there is no z incremental loop.
so how can i express arr[z].
i know i am sooo close!

You're close
: [code]
: int foo(int arr[])
: {
: int L = -10000;
: for (int x=0; x < SIZE; x++)
: {
: infile >> arr[x];
: if(arr[x] > L)
: L = arr[x];
: outfile<<setw(40) << arr[z] <<setw(6)<< L << endl;
: }
: return 0;
: }
: [/code]
:
:

• : :
: i'm not following you - in your code there is no z incremental loop.
: so how can i express arr[z].
: i know i am sooo close!
:
:
:
:
:
: You're close
: : [code]
: : int foo(int arr[])
: : {
: : int L = -10000;
: : [red][b]int ndx=0;[/red][/b]
: : for (int x=0; x < SIZE; x++)
: : {
: : infile >> arr[x];
: : if(arr[x] > L) [red][b]{
: : L = arr[x];
: : ndx=x; // ALSO tag the slot index!
: : }[/red][/b]
: : outfile<<setw(40) << arr[z] <<setw(6)<< L << endl;
: : }
: : return 0;
: : }
: : [/code]
: :
: :
:
:
[blue]Now [b]ndx[/b] will have the array index of the larges value.[/blue]
• THANKS ALOT!!

i'm not following you - in your code there is no z incremental loop.
: : so how can i express arr[z].
: : i know i am sooo close!
: :
: :
: :
: :
: :
: : You're close
: : : [code]
: : : int foo(int arr[])
: : : {
: : : int L = -10000;
: : : [red][b]int ndx=0;[/red][/b]
: : : for (int x=0; x < SIZE; x++)
: : : {
: : : infile >> arr[x];
: : : if(arr[x] > L) [red][b]{
: : : L = arr[x];
: : : ndx=x; // ALSO tag the slot index!
: : : }[/red][/b]
: : : outfile<<setw(40) << arr[z] <<setw(6)<< L << endl;
: : : }
: : : return 0;
: : : }
: : : [/code]
: : :
: : :
: :
: :
: [blue]Now [b]ndx[/b] will have the array index of the larges value.[/blue]
:

• Another loop is not necessary. Run that function in your compiler and see how it works.
• : thanks stober....
I did something really similar and it's working well:

Another loop is not necessary. Run that function in your compiler and see how it works.
: