Program Analysis

I was just seeing what you guys thought of my program; it returns an ordered list and some statistical information. I included it below.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <math.h>

using namespace std;


int main()
{
	int maxsize=9999999;
	cout<<"*******************************PROG STATISTICS*******************************\n";
	cout<<">>>Please enter #'s between 1 & "<<maxsize<<" for everything-DECIMALS WILL BE IGNORED"<<endl;
	cout<<">>>Enter the amount of numbers you want to analyze: ";
//get size array
int arraysize, countersec=0, meancount=0, Modecount=0, var=0, mean=0;
cin>>arraysize;
//
cout<<">>>Enter all numbers you want analysis on!"<<endl;
//input numbers for list
int numlist[arraysize];
int seclist[arraysize];

	for (int i=0; i<arraysize; i++)
	{
	cout<<"Number "<<i+1<<": ";
	cin>>numlist[i];
	if ((numlist[i]>maxsize) or (numlist[i]<1))
		{
		cout<<"Major error, you went too large idiot-Re Enter your number...\n";
		i--;
		}
	seclist[i]=0;
	}


for (int b=0; b<maxsize; b++)
{
for (int i=0; i<arraysize; i++)
	{
if (numlist[i]==b)
		{
	seclist[countersec]=numlist[i];
	countersec++;
		}
	}
}


cout<<"*******************************"<<endl<<endl<<"Ordered List=";

for (int i=0; i<arraysize; i++)
{
	meancount=meancount+seclist[i];
	cout<<seclist[i]<<"|";
}
mean=(meancount/arraysize);
cout<<"\nMean="<<(mean);

if ((arraysize % 2)==0)
{
	Modecount=(seclist[(arraysize/2)-1]+seclist[(arraysize/2)])/2;
}
if ((arraysize % 2)!=0)
{
	Modecount=seclist[(arraysize/2)]+.5;
}
cout<<"\nMode="<<Modecount<<endl;





for (int i=0; i<arraysize; i++)
{
	var=var+((seclist[i]-mean)*((seclist[i]-mean)));
}
var=(var/arraysize);
cout<<"Variance="<<var<<endl;

cout<<"Standard Deviation="<<sqrt(var)<<endl<<endl;

cout<<"*******************************";
}
Last edited on
Hi,

the code is great but

1
2
3
4
5
if ((numlist[i]>maxsize) or (numlist[i]<1))
		{
		cout<<"Major error, you went too large idiot-Re Enter your number...\n";
		i--;
		}


as you can see if user enters 0 then the program informs that the user went too large, this would stump anybody :)

also the code is neat, it will be neater if you would use user defined functions which will enhance the code readability

anyways overall the code is great
Hey,

Thank you. Just corrected that. Error now says too large/small. The other problem i seem to have is that if the user enters a number way too large, it will crash the program. Why is this?

Is this because the data can't properly fit in an "int" structure?
Last edited on
Topic archived. No new replies allowed.