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

Recommended Answers

All 4 Replies

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....

#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;
}

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];
}
Be a part of the DaniWeb community

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