I need help with finding the minimum value of x but I can't seem to get the code right. Please Help. Noob :sad:

``````#include<iostream>

using std::cout;
using std::cin;

int main()

{
int x;          // x is the duration of the call
double sum;
int number;
double average;
sum = 0;
number =1;
int max = 0;
int min = 0;

cout<<"Enter telephone call  " <<  number << ": ";

while (cin>>x)
{

if (x > max) // find longest call
{
max = x;
}

if (min < x)  // find shortest call ?
{
x = min;
}

sum += x; // sum = sum +
number++; // number = number + 1

cout<<"Enter telephone call  " <<  number << ": "; // keeps a space after the colon.

}// close while

average = sum/--number; //(number-1) I put the -- in front of number because
// subtract # before dividing.

cout<<"The Longest call in minutes is " << max;
cout<<"\nThe Shortest call in minutes is "<< min;
cout<<"\nThe Number of calls made are "<<number++;
cout<<"\nThe average time of the calls are "<< average;
cout<<'\n';
return 0;

} //close main``````

I need help with finding the minimum value of x but I can't seem to get the code right. Please Help. Noob :sad:

``````#include<iostream>

using std::cout;
using std::cin;

int main()

{
int x;          // x is the duration of the call
double sum;
int number;
double average;
sum = 0;
number =1;
int max = 0;
int min = 0;

cout<<"Enter telephone call  " <<  number << ": ";

while (cin>>x)
{

if (x > max) // find longest call
{
max = x;
}

if (min < x)  // find shortest call ?
{
x = min;
}

sum += x; // sum = sum +
number++; // number = number + 1

cout<<"Enter telephone call  " <<  number << ": "; // keeps a space after the colon.

}// close while

average = sum/--number; //(number-1) I put the -- in front of number because
// subtract # before dividing.

cout<<"The Longest call in minutes is " << max;
cout<<"\nThe Shortest call in minutes is "<< min;
cout<<"\nThe Number of calls made are "<<number++;
cout<<"\nThe average time of the calls are "<< average;
cout<<'\n';
return 0;

} //close main``````

Error is in if (min < x) section.

Should be if (x < min)
min = x

Otherwise you overwrite the value of x

Also, setting the min = 0 wont get you any new value for min, since the length of the call is always a positive number

Be a part of the DaniWeb community

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