retreiving the maxnum & minnum

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2004
Posts: 5
Reputation: newbeginney is an unknown quantity at this point 
Solved Threads: 0
newbeginney newbeginney is offline Offline
Newbie Poster

retreiving the maxnum & minnum

 
0
  #1
Jul 5th, 2004
can anyone explain to me a simple way to get the lowest input and the highest input From
multiple inputs
while also counting how many are below a certain value and avove a certain value
I am at my witts end tryng to learn. I am a newbie at programming and trying so many ways that I know are unneeded so far I have this

#include <iostream.h>
          main()
         {
               int totalCalls,callcounter,Duration;
               int longest, shortest;
               double average ;

         while(callcounter <= 10) //using ten as the  amount o call to easy use 
               {
                  cout << "Enter Call duration  :\n"; \\ lenght of calls 
                  cin   >> Duration ;\\ user input 
               
               totalcalls = totalcalls + duration;\\ adds duration to call total
               callcounter+ ; \\add one or every loop to counter 
          
               }//end while 

                 average = totalcalls/callcounter;\\ average of all calls 
                 if (duration ==5)
                    shortest = duration

               
              cout << " Average length of all calls :"<< average <<"\n";
              cout << " Total length of all calls  :"<< totalcalls<<"\n";
              cout << " Total of call\t :"<< callcounter<<"\n";
        }endmain


 
I can't seem to get the hang of getting the maximum legnth of calls and the miniumun length of calls also calls below and above a certain number
I have tried multiple if statements but am lost
I know it may be possible that I have to use arrays, switchs or a pointers
but as I have just started to learn C++ within the last two weeks any help is appreciated


< If it aint hard it it good >
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 141
Reputation: meabed is on a distinguished road 
Solved Threads: 3
Team Colleague
meabed's Avatar
meabed meabed is offline Offline
Junior Poster

Re: retreiving the maxnum & minnum

 
0
  #2
Jul 5th, 2004
this function get the minimum value for numbers that the user will input

#include<iostream.h>
using namespace std;
int min(const in *Numbers, const int Count)
{
int Minimum = Numbers[0];
for(int i = 0; i < Count; i++)
Minimum = Numbers[i];
return Minimum;
}
double Min(const double *Numbers, const int Count)
{
double Minimum = Numbers[0];
for(int i = 0; i < Count; i++)
if( Minimum > Numbers[i] )
Minimum = Numbers[i];
return Minimum;
}
double Min(const double *Numbers, const int Count)
{
double Minimum = Numbers[0];
for(int i = 0; i < Count; i++)
if( Minimum > Numbers[i] )
Minimum = Numbers[i];
return Minimum;
}
int main()
{
int Nbrs[] = { 12, 483, 748, 35, 478 };
int Total = sizeof(Nbrs) / sizeof(int);
int Minimum = Min(Nbrs, Total);
cout << "Minimum: " << Minimum << endl;
return 0;
}
Here is an example of running the program:
Minimum: 12Press any key to continue
Real Eyes Realize Real Lies
My Resume
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 34
Reputation: Fili is an unknown quantity at this point 
Solved Threads: 0
Fili's Avatar
Fili Fili is offline Offline
Light Poster

Re: retreiving the maxnum & minnum

 
0
  #3
Jul 5th, 2004
Hmm how about declaring 2 macros:
  1. #define max(a,b) a>b?a:b
  2. #define min(a,b) a<b?a:b
  3. int max,int min;
  4. ...
  5. max=max(x[0],x[1]);
  6. min=min(x[0],x[1]);
  7. for (i=2;i<n;i++)
  8. {
  9. max=max(max,x[i]);
  10. min=min(min,x[i]);
  11. }
  12. ...

I hope it's write since I didn't test it. :o
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 141
Reputation: meabed is on a distinguished road 
Solved Threads: 3
Team Colleague
meabed's Avatar
meabed meabed is offline Offline
Junior Poster

Re: retreiving the maxnum & minnum

 
0
  #4
Jul 5th, 2004
Real Eyes Realize Real Lies
My Resume
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 5
Reputation: newbeginney is an unknown quantity at this point 
Solved Threads: 0
newbeginney newbeginney is offline Offline
Newbie Poster

Re: retreiving the maxnum & minnum

 
0
  #5
Jul 8th, 2004
whoa there now I appreciate the help

that macro was a lil bit above my head
but I will look into that also meab thanks for the post
with maxnum function

I found something that was more simple to use

[code]

for (j=0;j >= 100 ;j++)
counter++

[\code]
this way I can keep count of all my inputs and determine the max and min

I think , But thanks to all who have contributed


<if it aint hard it aint right >
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 5
Reputation: newbeginney is an unknown quantity at this point 
Solved Threads: 0
newbeginney newbeginney is offline Offline
Newbie Poster

Re: retreiving the maxnum & minnum

 
0
  #6
Jul 8th, 2004
:lol: ok I have tried your way and and now I understand what you mean
it was basically the same :lol:











if it aint hard it aint right
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC