:?: 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 >

Dani AI

Generated

The original code has the right idea but a few concrete problems stop it from working: several variables are never initialized (for example callcounter and totalCalls), the counter increment is written as callcounter+ ; instead of callcounter++, and the average is computed with integer division. Initialize totals to 0, increment the counter properly, and either initialize min/max from the first input or use safe sentinels from <limits>. As discovered, once those basics are fixed the rest is straightforward.

A simple, robust pattern is: read the first duration and set min and max to it, then loop over the remaining inputs updating min, max, total, and the below/above counters. Input validation prevents bad values from breaking the loop. Example:

#include <iostream>
#include <limits>

int main() {
    std::cout << "How many calls? ";
    int N; if(!(std::cin >> N) || N <= 0) return 0;

    int dur; std::cout << "Enter duration 1: "; std::cin >> dur;
    int minDur = dur, maxDur = dur;
    long long sum = dur;
    int below = 0, above = 0;
    const int threshold = 5;

    if(dur < threshold) ++below; else if(dur > threshold) ++above;

    for(int i = 1; i < N; ++i) {
        std::cout << "Enter duration " << (i+1) << ": ";
        if(!(std::cin >> dur)) { std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); --i; continue; }
        if(dur < minDur) minDur = dur;
        if(dur > maxDur) maxDur = dur;
        sum += dur;
        if(dur < threshold) ++below; else if(dur > threshold) ++above;
    }

    double avg = static_cast<double>(sum) / N;
    std::cout << "Min: " << minDur << " Max: " << maxDur << " Avg: " << avg << " Below: " << below << " Above: " << above << "\n";
    return 0;
}

Notes and debugging checklist: avoid macros for min/max (they can cause subtle bugs) — prefer direct comparisons or std::min/std::max; if the count N is unknown use a sentinel value or while (std::cin >> dur); always check cin state; cast before dividing to get a floating-point average; and prefer a larger integer type for the running sum if inputs can be large. ’s iterative idea is the right pattern; ’s array-based min function is useful when you need to store values instead of processing them as they arrive.

Recommended Answers

All 5 Replies

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;
return Minimum;
}
double Min(const double *Numbers, const int Count)
{
double Minimum = Numbers[0];
for(int i = 0; i < Count; i++)
if( Minimum > Numbers )
Minimum = Numbers;
return Minimum;
}
double Min(const double *Numbers, const int Count)
{
double Minimum = Numbers[0];
for(int i = 0; i < Count; i++)
if( Minimum > Numbers )
Minimum = Numbers;
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

Hmm how about declaring 2 macros:

#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
int max,int min;
...
max=max(x[0],x[1]);
min=min(x[0],x[1]);
for (i=2;i<n;i++)
   {
     max=max(max,x[i]);
     min=min(min,x[i]);
   }
...

I hope it's write since I didn't test it. :o

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

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

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 >

: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

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.