954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

c++ arrays, help identify element place

I have to identify which element in the array the highest and lowest numbers are. I have finished the rest of the project but you can see that i need help with the element position. Here's what i have and thank you, thank you, thank you
#include
#include"apvector.h"//didn't inclue io manipulators because working with int

int main()
{
int high;
int low; //declare variables
int sum;
int average;
int num_values;
int index;
high=1; //initialize variables
low=1;
sum=1;

cout<<"Please enter a number. "<> num_values;
cout<<"Enter values for the array of "<value(num_values); //declare array

for(index = 0; index <= (num_values - 1); index++)//loop to get values to
//fill array
{
cout << "Enter the number for space " << index + 1 << ": ";
cin >> value[index]; //input of values to fill array

if (value[index]>high)
{high=value[index];} //assign new values to low and high
if (value[index]

Guppy25
Newbie Poster
4 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

Declare 2 more variables

int max_pos=0, min_pos=0;
................

if (value[index]>high)
{
high=value[index];
max_pos = index;
}   //assign new values to low and high
if (value[index]<low)
{
low=value[index];
min_pos = index;
}
.....................
cout<<"the largest number is " <<high<<
         " and its element position is " <<max_pos  <<endl;
cout<<"the smallest number is " <<low<<   
          " and its element position is " <<min_pos   <<endl;
frrossk
Posting Whiz in Training
220 posts since Sep 2004
Reputation Points: 17
Solved Threads: 9
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You