0

If i have 5 int variables with values stored in them, is there a command to find the lowest valued variable?

3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by financeSEObegin
0

Is there an easier way? The assignment wants me to use one function to get the number of accidents in five areas from the user, and use another to determines which has the lowest amount of accidents which is called in main... Just not sure how to set it up....

0
#include <iostream>
#include <algorithm>
using namespace std;

#define MAX_NUMBERS 5

int main() {
	int input_numbers[MAX_NUMBERS];
	for(size_t i = 0; i < MAX_NUMBERS; ++i){
		cout << "Enter number " << i+1 << ": ";
		cin >> input_numbers[i];
		cin.ignore(255, '\n');
	}
	cout << "The smallest element is " << *min_element(input_numbers,input_numbers+MAX_NUMBERS) << endl;
	return 0;
}
0

if I understand your question, this is all you need...
btw i like post #4, but i have a feeling he wants something easier :P

int number[5];
int min = 9999999;
for(int i = 0; i<5; i++)
{
  cout << "enter number ";
  cin << number[i];
  if (number[i] < min)
        min = number[i];
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.