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 8262973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:56:12+00:00 2026-06-08T03:56:12+00:00

I’m having a serious output problem with a program i made for my homework.

  • 0

I’m having a serious output problem with a program i made for my homework. Below is the code I’m using to calculate the mean and standard deviation for a group of numbers given by the user, until a flag value of -1 is reached. I am not allowed to use arrays. I am supposed to use a formula (for the std dev part) given by my professor which is ((sum (xi)^n) – ((sum xi) ^2/ n) /(n-1)) xi is x sub i, which is each input. I am using visual studio 2010 on a win7 x64 vm on my macbook pro (doubt this has anything to do, but just in case).

below is the code (followed by the screen cap of the error)

#include<iostream>
#include <cmath>
using namespace std;


int i;

int sum_unkown_vars();
double std_dev(int sum, int n);

/*double std_dev(int sum, int n)
{
double dev;

dev = sqrt(((pow(sum, 2.0)-(pow(sum, 2.0)/n)))/(n-1));

return dev;
}*/

int sum_unkown_vars()
{
i = 0;
int n;
int sum1 = 0;
int sum_sqd = 0;
double sdev;

cout<<"This part will sum variables given by user until flag value of -1"<<endl;

cout<<"\nNext Variable Please: ";
cin >> n;
while(n != -1)
{

    sum_sqd = sum_sqd + n*n;
    sum1 = sum1 + n;
    i++;
    cout<<"\nNext Variable Please: ";
    cin >> n;
}

cout <<"\nNumber of variables is "<< i <<endl
    <<"Sum of variables is "<< sum1 <<endl;

sdev = sqrt(((sum_sqd*1.0)-(1.0*pow(sum1, 2.0)/n))/(n*1.0-1.0));

cout <<"\nStandard Deviation is "<< sdev << endl;

return sum1;
}



int main()
{
int sum = 0;
int j;
double avg;
double std_dev1;

cout<<"This program will take integers given by the user,"
    <<"\nsum them, then find average and standard deviation\n\n";

sum = sum_unkown_vars();

//cout <<"\nPlease enter number of integers previously given: ";
//cin >> j;

avg = sum / (i*1.0);

cout <<"\nAverage is: "<<avg<<endl;

//std_dev1 = std_dev(sum, i);

//cout <<"Standard Deviation is : "<< std_dev1 <<endl;



system("pause");
return 0;

}

screen capture

Thanks in advance for any help received

  • 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-08T03:56:15+00:00Added an answer on June 8, 2026 at 3:56 am

    The variable n in the formula

    ((sum (xi)^n) - ((sum xi) ^2/ n) /(n-1))
    

    And the variable ‘n’ in the function

    sum_unkown_vars()
    

    are not the same. The n in the formula indicates the number of elements and this is defined by the variable ‘i’ in your program. Please correct this first.

    Additionally number of variables should be either i+1 or you should increment i just after the initial reading.

    I think there are still more errors in the code. e.g, you don’t return the standard deviation from the function, you are using integer to return the standard deviation etc. Please debug the rest yourself with a debugger. Please make an expectation for the values and cross check it in the debugger.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.