Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9165139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:50:40+00:00 2026-06-17T14:50:40+00:00

I am trying to write a second function to calculate a vector of integers

  • 0

I am trying to write a second function to calculate a vector of integers which is in the main function. My vector is set up like this.

int inputinfo;
cout << "\nPlease enter in scores: ";
cout << "\nEnd your input with ctrl-z\n";
vector<int> scores;
    while (cin >> inputinfo)
    {
        scores.push_back(inputinfo);
    }

Here is my median equation (which I am not sure is working right). I would like to make a function for median and then call it back to the main function to find the median of the vector.

  double median;
  size_t size = scores.size();

  sort(scores.begin(), scores.end());

  if (size  % TWO == 0)
  {
      median = (scores[size / 2 - 1] + scores[size / 2]) / 2;
  }
  else 
  {
      median = scores[size / 2];
  }

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:50:41+00:00Added an answer on June 17, 2026 at 2:50 pm

    Check whether your code fails if thee is none or only one number in the vector. You can fix this using

    if (size==0) throw "Vector empty";
    if (size==1) return scores[0];
    

    before the if (size % TWO == 0) line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello everyone I'm trying to write function which can unfold int in the list
I've had problem when trying write a function which has a default value when
I'm trying to write a function to update the multiple select (the second one
I'm trying to write a function which re-uses the implicit conversions which I have
I'm trying to write a variadic function composition function. Which is basically the (.)
I am trying to write a function that will set the first argument to
I'm trying to write good round_double function which will round double in specified precision:
I'm trying to write a function in Python (still a noob!) which returns indices
I am trying to write a function to calculate the number of atoms in
I'm trying to write a function that gets a path and returns this file's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.