hi plz i have a problem i have a h.w to be done & my code have something wrong so plz try to help me
the program wants the user to enter numbers until the user user enters a negative number then the program stops & output : max. no. ,min no. & avg .
& here is the code :
#include<iostre am>
using namespace std;
void main()
{
float n=1;
float x;
float max;
float min;
cout<<"Enter the numbers separated by spaces: ";
cin>>x;
if(x>=0)
{max=x;
min=x;}
cin>>x;
while(x>=0)
{
if(x>max)
max=x;
if(x<min)
min=x;
cin>>x;
n++;
}
float avg=1;
float sum=0;
sum=sum+x;
avg=sum/n;
cout <<"Maximum:"<<m ax<<endl<<"Mini mum:"<<min<<end l<<"Average:"<< avg<<endl;
}
so what's wrong with it plz answer me as soon as u can
the program wants the user to enter numbers until the user user enters a negative number then the program stops & output : max. no. ,min no. & avg .
& here is the code :
#include<iostre am>
using namespace std;
void main()
{
float n=1;
float x;
float max;
float min;
cout<<"Enter the numbers separated by spaces: ";
cin>>x;
if(x>=0)
{max=x;
min=x;}
cin>>x;
while(x>=0)
{
if(x>max)
max=x;
if(x<min)
min=x;
cin>>x;
n++;
}
float avg=1;
float sum=0;
sum=sum+x;
avg=sum/n;
cout <<"Maximum:"<<m ax<<endl<<"Mini mum:"<<min<<end l<<"Average:"<< avg<<endl;
}
so what's wrong with it plz answer me as soon as u can
Comment