Hi everyone, I want to know how we can make the program print the the max value from several data that user have inputed, for example I have the user input 5 integer :
1. 15
2. 35
3. 66
4. 13
5. 41
And the program should print 66 because it's the max value(or the biggest value).
Actually I have solve this problem with my code, here's the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <iostream>
int main ()
{
std::cout<<"Enter 5 number: " << std::endl;
int number[5];
// Store data
for (int i=0; i<5; i++)
{
std::cout<< i+1 << ". " << ": ";
std::cin >> number[i];
}
int Max=0;
// Search the max number
for (int j=0; j<5; j++)
{
if (number[Max] < number[j])
Max=j;
}
std::cout << "The max number is: " << number[Max]
<< std::endl;
return 0;
}
|
But my friend teasing me and told me like this, you can do that because you know(or you tell the user) to input the data 5 times, what if you didn't know how many data that must be stored by the user ?
Then she told me about using a function and something about
va_list, va_arg and also about using stdarg.h header
But seriously I don't know anything about this, and I hope someone willing to help me, I don't need the source code(but if you kind enough thanks ^_^), I just need a little explanation about this, probably you can direct me to a link with a discussion about this function.
Regardless anything, thank you very much, and I'm sorry if I make a bad question or something like that, because I'm a beginner.. Peace all.
P.S: I'm sorry but if you're going to tell me about asking my friend that told me about these functions, that's I can't do because she won't tell me, that's why I'm here now -_-