Hello my name is Leonard E. Norwood Jr.

I haven't been back much but I'm still studying and practicing C++

I'm still doing arrays starting from beginning to better get used it it.

Anyway, it's a simple program of finding the largest number of the 10 numbers. I know my math well, but something is under my nose to fix this problem. First of all, I sometimes get the max number correctly out of different kinds of numbers, at times it doesn't unless I fix it up a little. Second, trying to find the element where the highest number in the list is located. Also, the array name is wrong as it is called grade, but supposed to be fmax, standing for find max, I can fix that easily. I'm just getting stomped on mostly number 2 problem, finding the element of the value of the highest number and display it. Does anybody understand what I'm saying.

I haven't done much big problems lately since I'm still practicing and working out the errors until I'm confident enough. Anyway...that's all.

``````#include <iostream>
using namespace std;

int main()
{

const int NUMES = 10;

cout << "In this program, you will enter ten integer numbers and this program"
"will find the maximum value of these ten numbers. " << endl;

for(i = 0; i < NUMES; i++)
{
cout << "Enter a grade: ";

}

cout << "The maximum value of the numbers is: " << max << endl;
cout << "The element number is " << i << " in the list of numbers. " << endl;

system("pause");
return 0;
}
``````

You need to have another counter that stores the index value of the highest number then add another line to the if statement on line 20 to set that integer to the current value of i loop counter. Don't forget to put { and } around that if statement.

Hey Nekoleon!

Someone on here pointed me in the direction of vectors some time ago and would like to pass on the wisdom!

Here is some quick code that solves your problem using vectors, something you should definatly look into!

``````#include <iostream>
#include <vector> //Needed to implement …``````

## All 7 Replies

You need to have another counter that stores the index value of the highest number then add another line to the if statement on line 20 to set that integer to the current value of i loop counter. Don't forget to put { and } around that if statement.

All you need to do is divide the program in two halves,before doing it find out the average value of the input numbers;compare the numbers with the average value and sort lesser numbers with the average value to one side and higher numbers to the other side and sort them. Recursive way of sorting has to be done

i will show you with an example

assume input numbers are 6,78,49,50,22,44,89,90,2,1

The average value is 43.1 compare the numbers
6<43 if true store it an array say lesser_array[]
78<43 if false store it another array greater_array[]

you will get two arrays and sort those arrays individually with the same technique, though it is sophistcated,you will get the desired output

All you need to do is divide the program in two halves ...

Too complicated for such a small program. Another example of hitting a nail with a sludge hammer.

Hey Nekoleon!

Someone on here pointed me in the direction of vectors some time ago and would like to pass on the wisdom!

Here is some quick code that solves your problem using vectors, something you should definatly look into!

``````#include <iostream>
#include <vector> //Needed to implement vectors
#include <algorithm> //needed to run sort() (line 23)

using namespace std;

int main()
{
vector <int> numbers; //create a vector of integers
int numEntered; //used to get the users input

cout << "Enter 10 Digits: " << endl;

for(int i = 0; i < 10; i++) {

cin >> numEntered; //loop through 10 times taking user input

numbers.push_back(numEntered); //each loop store the input in the vector we made

}

sort(numbers.begin(), numbers.end());//sort the vector of integers lowest to highest

//the 9th element (0-9) will always be the highest number due to sorting
cout << "Highest Number Entered: " << numbers.at(9) << endl;

}
``````

Hope this helps in the future!

commented: sludge hammer! +0
``````#include <iostream>

using namespace std;

int main() {
const int NUMES = 10;
int max = 0, i, grade[NUMES];

cout << "In this program, you will enter ten integer numbers and this program will find the maximum value of these ten numbers. " << endl;

for(i = 0; i < NUMES; i++) {
cout << "Enter a grade: ";
if (grade[i] == -1) break; //if someone enters -1, exit
}

cout << "The maximum value of the numbers is: " << max << endl;
cout << "The element number is " << i << " in the list of numbers. " << endl;

return 0;
}
``````

u can use even a bubble sort and find the last element so that will be the greatest

I'm still doing arrays starting from beginning to better get used it it.

Therefore speakon's code violate your major parameter -- using arrays.

phani1092 actually has the answer with "All you need to do is divide the program in two halves". The rest of his post though goes off track in a major way.

Programs should not mix processes. It makes them difficult to debug, and, as you have seen, difficult to write.

You have 3 defined processes:
1) input values
2) find max
3) output max

Separate your posted program into these 3 sections and the code you originally posted is very close.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.