#pragma once
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
usingnamespace std;
int main()
{
//declare an array
float numbers [10];
double sum;
double mean;
double standardDeviation;
double sdresult;
double mode;
float AA;
//storing 30 numbers entered by user in an array
cout<<"enter thirty floating point numbers";
//compute sum, mean
for (int i = 0; i < 10; i++)
{
cin >> numbers[10];
sum += numbers[10];
mean = sum /10;
AA += pow(numbers[10] - mean,2);
//standardDeviation += pow(numbers[i] - mean, 2);
}
sdresult = sqrt(AA / 10);
cout<<"sum="<<sum <<endl;
cout<<"mean="<<mean <<endl;
cout<<"standard Deviation = " <<sdresult;
//compute mode
double count = 1;
double countMode = 1;
for (int i=1; i<30; ++i)
{
if(numbers[30]== i)
{//count occurrence of the current number
++count;
}//end if
else
{//now this is a different number
if(count>countMode);
{
countMode = count; //mode is the highest occurrence
mode = i;
}//end if
count = 1; //reset count for the new number
i = numbers[30];
}//end else
}
cout<<"mode="<<mode <<endl;
return 0;
}
Looks like your'e reaching an uninitialized arg on numbers[10].
Watch out as this can lead into a lot of errors if you don't recognize it as fast as possible.
If detecting those kind of bugs becomes a hard job there are program that can help you do that. I tend to use checkmarx sometimes but there are more. Anyway, it's recommended to learn how to detect those also by yourself.
Good luck!
but how can i find the mode, this formula doesn't seem to give me my mode although the numbers entered are repeated
as for the standard deviation i have tried [i] as well as [10] none of them give me the answer that i get while doing the manual std dev
i have now managed to get here but now it gives me one error on line 36 saying subscript is not if integral type
i am so sorry i am very new to this and got to submit this today but i am honestly stuck
your assistance will be highly appreciated... thank you