4 Replies - 18322 Views - Last Post: 03 March 2009 - 04:33 AM Rate Topic: -----

#1 ejiroy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • 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  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#3 ejiroy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • 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
Was This Post Helpful? 0
  • +
  • -

#4 ejiroy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 22-February 09

Re: Minimum Value Function

Posted 02 March 2009 - 10:49 PM

the program doesn't seem to work right
Was This Post Helpful? 0
  • +
  • -

#5 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 275
  • View blog
  • Posts: 1,778
  • Joined: 20-September 08

Re: Minimum Value Function

Posted 03 March 2009 - 04:33 AM

View Postejiroy, 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 had a semi-colon after your function top line ...
(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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1