i am writing a program on statistics but dont seem to see where my errors are

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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "stdafx.h"
#include "array1.h"
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;
void main()
{
	//declare an array
	float numbers [30]; 
	float sum;
	float mean;
	float standardDeviation;
	float mode;

	//storing 30 numbers entered by user in an array
	cout<<"enter thirty floating point numbers";

	//compute sum
	for (float i = 0; i < 30; ++i) 
	{
        cin >> numbers[i];
        sum += numbers[i];
    }
	cout<<"sum="<<sum<<endl;

	//compute mean
	float n, i;
    float numbers [30], sum=0.0, mean;

    cout << "Enter the numbers of data: ";
    cin >> n;

    while (n > 30 || n <= 0)
    {
        cout << "Error! number should in range of (1 to 30)." << endl;
        cout << "Enter the number again: ";
        cin >> n;
    }//while end

    for(i = 0; i < n; ++i)
    {
        cout << i + 1 << ". Enter number: ";
        cin >> num[i];
        sum += num[i];
    }

    mean = sum / n;

	cout<<"mean="<<mean<<endl;

	//compute standard deviation
	float i;
    float numbers [30];

    cout << "Enter 30 floating point numbers: ";
    for(i = 0; i < 30; ++i)
	{
        cin >> numbers[i];
	}
    cout << endl << "Standard Deviation = " << calculateSD(numbers);

    return 0;

	float calculateSD(float numbers[])
	{
    float sum = 0.0, mean, standardDeviation = 0.0;

    float i;

    for(i = 0; i < 30; ++i)
    {
        sum += numbers[i];
    }

    mean = sum/30;

    for(i = 0; i < 30; ++i)
    {
		standardDeviation += pow(numbers[i] - mean, 2);
	}
		return sqrt(standardDeviation / 30);

	cout<<"standardDeviation="<<standardDeviation<<endl;

	//compute mode
	float = numbers[30];
	float mode= number;
	float count= 1;
	float countMode=1;
	for (float i=1;i<30;i++)
	{
		if(numbers[i]==number)
		{//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=number;
			}//end if
			count=1; //reset count for the new number
			number= numbers[i];
		}
	}
	cout<<"mode="<<mode<<endl;

	return 0;
};
Last edited on
i get the following errors, please assist me on how to solve the errors

1> array1.cpp
1>c:\users\lubna\documents\visual studio 2010\projects\array1\array1.h(12): error C2059: syntax error : ')'
1>c:\users\lubna\documents\visual studio 2010\projects\array1\array1.h(13): error C2143: syntax error : missing ';' before '{'
1>c:\users\lubna\documents\visual studio 2010\projects\array1\array1.h(13): error C2447: '{' : missing function header (old-style formal list?)
1>array1.cpp(117): fatal error C1004: unexpected end-of-file found
Where is line 12 of array1.h?

Please use code tags when posting code.

Also main() must return an int in C++ (int main()).
Line 2: Where is array1.h?

Line 8: main() must be type int.

Line 21,42: Use an int, not a float for an index. floats are approximations.
Lines 23-24,45-46,60,75,82,95,107: Subscripts must be an integral type.

Line 30: Duplicate definition of numbers, sum and mean.

Line 45-46: num is undefined. Did you mean numbers?

Line 54-55: Duplicate definitions of i and numbers.

Line 64: You can't return a value in a void function. If you fix the type of main(), this line is correct.

Line 65: Missing a } to terminate main.

Line 89: Extraneous =.

Line 90: number is undefined.

Line 62: No function prototype for calculateSD().

Line 101: Extraneous ;

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.







Hello lubzy95,

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

You should try fixing all the errors you can before you post your program. There are several errors in main that jlb did not mention.

Your first for loop t line 20 for (float i = 0;...) does not need to be a float it is only a counting number. "size_t or int" will work fine. I use "size_t" because many functions on the rhs of < return a "size_t" which is another name for an unsigned int and the number of bytes for storage depends on the computer it is run on.

"double"s are more often preferred than "float"s the precision is better.

"main" does not have a closing "}" and the semi-colon at the end of the program is not needed.

Line 63 the "return 0;" is not needed there.

The function starting at line 65 (float calculateSD) should not be there. Either before main or after main. Second it is hard to tell where the function ends. It looks like it ends at line 110, but that line also looks like the end of main. Line 82 will leave the function, so if the rest of the code is part of the function it will never be reached.

The semi-colon on line 111 should not be there.

As jlb says without seeing what is in the array1.h file it makes it hard to know what is wrong.

Hope that helps,

Andy
thanx alot for your response i am very new to this but i will use all your remarks and see how i can go about it thanx alot
Topic archived. No new replies allowed.