# Minimum Value Function

Page 1 of 1

## 4 Replies - 25379 Views - Last Post: 03 March 2009 - 04:33 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=90216&amp;s=f27030637ff4fd632b0c75759aa879d9&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 ejiroy

Reputation: 0
• Posts: 35
• Joined: 22-February 09

# Minimum Value Function

Posted 02 March 2009 - 08:39 PM

This program that uses a function to determine the Minimum value of a set of 10 numbers.
I cant figure out the parse error in Line 5 or 4, and am I doing this right.
```#include <iostream>
using namespace std;

float MinValue(float List);
{
int Num=0, i=0, Min=0, i++;
while(i>List)
{
if(Num>Min)
Min=Num;
}
return MinValue
}
main()
{
cout << "Enter number:";
cout << "The minimum number is:" << MinValue(10) << endl;
}

```

Is This A Good Question/Topic? 0

## Replies To: Minimum Value Function

### #2 OrganizedChaos

Reputation: 39
• Posts: 153
• Joined: 29-November 08

## Re: Minimum Value Function

Posted 02 March 2009 - 08:51 PM

Unfortunately you're not doing it right. In order to be able to find the minimum value, you need an actual list of numbers. This can be done by creating an array of numbers.
```#include <iostream>
using namespace std;
int main() { //function main returns an int value
int numArray[10]; //Creates array of 10 values
int num; //Creates variable num
for (int x = 0; x < 10; x++){ //loops 10 times
cout << "Enter number: ";
cin >> num;
numArray[x] = num; //num gets put into position x in the array
}
cout << "The minimum value in the set is: " << findMinValue(numArray) << endl; //Output minimum value

system("pause"); //pauses system to view results
return 0;
}

```

Now, to find the minimum of those values that you entered:
```int findMinValue(numArray[]){
int minValue = numArray[0]; //first value in array is lowest to start
for (int x = 1; x < 10; x++){
if (numArray[x] < minValue) //if value at x is lower than minValue
minValue = numArray[x]; //minValue gets value at x
}
return minValue;
}

```

Hope this helps

This post has been edited by OrganizedChaos: 02 March 2009 - 08:53 PM

### #3 ejiroy

Reputation: 0
• Posts: 35
• Joined: 22-February 09

## Re: Minimum Value Function

Posted 02 March 2009 - 09:00 PM

I was thinking about putting in an array, but can you help me figure out what the parse error is still, thanx for your help

### #4 ejiroy

Reputation: 0
• Posts: 35
• Joined: 22-February 09

## Re: Minimum Value Function

Posted 02 March 2009 - 10:49 PM

the program doesn't seem to work right

### #5 David W

• DIC supporter

Reputation: 298
• Posts: 1,839
• Joined: 20-September 08

## Re: Minimum Value Function

Posted 03 March 2009 - 04:33 AM

ejiroy, on 2 Mar, 2009 - 09:49 PM, said:

the program doesn't seem to work right

You need int main() .... you left off 'int'

(You use a semi-colon there ONLY for the prototype line.)

This may give you a start ...

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

float minValue( float ary[], int size ) // ; <-- this semi-colon was an error
{
if( size < 1 ) return 0;

float min = ary[0]; // pick first actual value for a 'min' ...to get started

// then check the rest ... and update min as necessary ...
for( int i=1; i<size; ++i ) if( ary[i] < min ) min = ary[i];

// ok ... return it
return min;
}

int main() // need 'int main()' // you just had main ...
{
float myAry[] = {1.0, 30.0, -5.1, 33.9, -7.77, 111.9};

cout << "The minimum number is "
<< minValue( myAry, sizeof myAry / sizeof myAry[0] )

<< "\n\nPress 'Enter' to exit ... " << flush;
cin.get();
}
```

BTW ... you may like to see the new free C++ e-text at ...

http://developers-he.../index.p...opic,127.0.html