# Thread: Stuck on creating a program with array

1. ## Stuck on creating a program with array

Hey there! I am a beginner with C++ and has now begun to learn me how arrays works but I'm stuck on a practice problem and the program them wants me to do is to:

Write a program that takes in 50 values and prints out the highest, the lowest, the average and then all 50 input values, one per line.

I am totally stuck at this practice problem the only code I could write was this:

Code:
```#include <iostream>
using namespace std;
int main()
{
int value[50];
for (int i = 0; i < 50; i++)
{
cout << "Enter value " << i << ": \n";
cin >> value[i];
}
}```
I'm do not know how to do so the program prints out which number was the highest, lowest and the averange and then all 50 input values. Can somebody help me how to do this?, Please.

2. I have a variable named max. I initialize it to a very big negative number. Let's say, -100.
I ask you to give me 3 numbers.
You give me the first, 3. I compare it with max and I choose the greatest of these two and I assign this to max. Now max is 3, since 3 > - 100.
Then you give me 2. I compare 2 with max (which is 3) and I see that 2<max so I do nothing.
You give me 10. I compare 10 with max(which is 10) and I see that 10>max so I assign ten to variable max.
End of procedure.
Max holds the greatest number you gave me.

Try to implement this for a start

3. What you should start with is the logic required for such a thing. Implement it in pseudo code or a flow chart.

4. std10093: I read your comment and that helped me a little bit to get started by writing the code.

But I'm still not knows exactly how to do the code I have written so far is:

Code:
```#include <iostream>
using namespace std;
int main()
{
int number[3];
for (int i = 0; i < 3; i++)
{
cout << "Give me 3 numbers " << i << ": \n";
cin >> number[i];
}
if (number[0] > number[1])
{
cin << number[0];
}
else if (number[1] > number[0])
{
cout << number[1];
}
for (int j = 0; j < 47; j++)
{
cout << '\n';
cout << j;
}
}```
I knows i needs something that I need to compare how big and low all 3 numbers is so the program can now which number that is the higest and print it out first and then the lowest, the average. but I do not know how to write that can somebody give me a hint or something?.

5. See above reply. Use a flowchart.

6. Originally Posted by DecoratorFawn82
std10093: I read your comment and that helped me a little bit to get started by writing the code.

I knows i needs something that I need to compare how big and low all 3 numbers is so the program can now which number that is the higest and print it out first and then the lowest, the average. but I do not know how to write that can somebody give me a hint or something?.
I suggest re-reading the post, again.

Tim S.

Originally Posted by std10093
I have a variable named max. I initialize it to a very big negative number. Let's say, -100.
I ask you to give me 3 numbers.
You give me the first, 3. I compare it with max and I choose the greatest of these two and I assign this to max. Now max is 3, since 3 > - 100.
Then you give me 2. I compare 2 with max (which is 3) and I see that 2<max so I do nothing.
You give me 10. I compare 10 with max(which is 10) and I see that 10>max so I assign ten to variable max.
End of procedure.
Max holds the greatest number you gave me.

Try to implement this for a start

7. Ok it seems that you are trying, so read the code I provide below and refer to post #2 for the logic.

Code:
```#include <iostream>

using namespace std;

int main()
{
int max = -1000; // Initialize max with a really small value
int input;

// Now read three integers from input
for(int i = 0 ; i < 3 ; i++)
{
cout << "Input" << endl;
cin >> input;
if(input > max)
{
max = input;
}
}

cout << "Max is " << max << endl;

return 0;
}```
If you just copy paste the code, then you won't get the logic, thus you won't implement the code to find min. If you do what I said in first sentence of this post, then you will be able to do it. I hope you will

8. Don't hand out solutions--especially logic!
The OP must be able to come up with something as simple as this on his/her own, not guided by some invisible hand. The OP will learn nothing by being fed code.

9. It's a chance for him to get a boost and see how the logic I explained on post #2 is implemented. That can give a good student that is really stuck the chance to go on. If he is not in this group he simply copy paste the code and then nothing. Moreover, the answers I saw did not see enough to help. If I was him, I couldn't be helped by them.

10. Originally Posted by std10093
...That can give a good student that is really stuck the chance to go on.
And help a student learn absolutely nothing.

Moreover, the answers I saw did not see enough to help. If I was him, I couldn't be helped by them.
What??? How is being able to make a simple flowchart too difficult or non-helping? This is basics of basics! This is something they absolutely should know. If they don't, then it's time to learn.
The OP has made no effort in trying to demonstrate any effort into actually making a flowchart. Therefore, it is wrong to give out any sort of code.
This is an exercise in itself. To take your problem, make a flowchart, then implement that code.
Sure, the OP may not know how to translate a flowchart into code--we could help with that, if the OP has show willingness to actually do something him/herself.

11. std10093: I have understand your code and it's working. What it does is of course output the highest number. But I must think of self how to do so the program knows what the lowest number is and the average. I got the code that prints out the highest and the lowest number and the code is this:
Code:
```#include <iostream>
using namespace std;
int main()
{
int max = -1000;
int lowest = 1000;
int input;

for (int i = 1; i < 4; i++)
{
cout << "Input " << i << ": ";
cin >> input;
if (input > max)
{
max = input;
}
if (input < lowest)
{
lowest = input;
}
}
cout << "Max is: " << max << '\n';
cout << "Lowest is: " << lowest << '\n';

return 0;
}```
But have still problem with the average. I guess it has something with "max" to do if I'm not have understand this wrong.

12. Again, do a flowchart. Jot down how you'd do it in real life to get the hang of it.
Don't avoid it. It's not hard, and it will help you a ton.

13. Originally Posted by std10093
Ok it seems that you are trying, so read the code I provide below and refer to post #2 for the logic.

...

If you just copy paste the code, then you won't get the logic, thus you won't implement the code to find min. If you do what I said in first sentence of this post, then you will be able to do it. I hope you will
Give a man a fish, and he eats for a day. Teach a man....bla bla you know the rest.

Besides, your solution is incorrect. What if only numbers below -1000 was entered? Then the program will say that the largest value entered is -1000, and the user will be calling OP in the middle of the night screaming for a refund. Also, your (faulty) solution uses magic numbers. If someone came across this code, without already knowing what it is supposed to be doing, the -1000 would be a mystery.

So not only are you denying OP the opportunity to solve this problem for himself, you are providing him with a faulty and subpar solution that he will undoubtedly copy/paste without question.

14. To help with the math.
Average equals the sum divided by the number of items.

Tim S.

15. Have still not figured out what to do in this case. The first ones to get the higest number and the lowest numbers are actually very easy to do it's just to initialize the variable max to a really low value and variable lowest to a really high value. It's just to use the signs < & > that means lesser and greater. But the third I do not know which sign I will use tried to use the / sign to divide something with the input values.

stdhta01: Average equals the sum divided by the number of items. What are you meaning with number of items is it the number of how many input values?. Still stuck on this still needing more help with it.