I'm supposed to write a program in which a user will input a list of numbers into a vector. the program will run and...
i was able to get it to this but i still dont know how to add the average formula and the median formula to the code
- output the list of numbers put into the vector
- identify the highest and lowest number in the list
- find the sum of the numbers
- and find the median of the list
i was able to get it to this but i still dont know how to add the average formula and the median formula to the code
Code:
#include <iostream>
#include <vector>
int main()
{
std::vector <double> values;
std::cout<<"Enter Values, 0 To Quit:\n";
bool more= true;
while(more){
double s;
std::cin>>s;
if(s==0)
more=false;
else
values.push_back(s);
}
double highest= values[0];
double lowest= values[0];
int i;
for(i=1;i<values.size(); i++)
if(values[i]>highest)
highest=values[i];
else if(values[i]<lowest)
lowest=values[i];
for(i=0; i<values.size(); i++)
{
std::cout<<values[i];
if(values[i]==highest)
std::cout<<" <== Highest Value";
if(values[i]==lowest)
std::cout<<" <== Lowest Value";
std::cout<<"\n";
}
{ if (values.size() == 0) return 0;
double sum = 0;
for (int i = 0; i < values.size(); i++)
sum = sum + values[i];
return sum / values.size();}
return 0;
}
Comment