What Am I doing wrong

Forget the standard diaviation for now. Why isnt this working?

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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

//Symbolic Constants

const int MIN_VALUE = -100;            //The smallest possible number
const int MAX_VALUE = 100;             //The largest possible number


int getValue( int lowerBound, int upperBound );
float findLow(float,float,float,float);
float findHigh(float,float,float,float);
float calcSum(float,float,float,float);
float calcMean(float,float,float,float);
float calcStdDev(float,float,float,float);


//Put the function prototypes here


int main()
{

/**********************************************************************
Variable Dictionary

num1, num2, num3, num4      The 4 numbers that are enteded by the user

sum                         The calculated sum

highNum, lowNum             The largest and smallest numbers

avg                         The calculated average

stdDev                      The calculated standard deviation

again                       The user's choice for continuation
**********************************************************************/

int num1, num2, num3, num4;
int sum, highNum, lowNum;
double avg, stdDev;

char again = 'Y';

cout << fixed << setprecision(3);


//While the user wants to perform calculations

	while( again == 'Y' or again == 'y' )
{

  //Get 4 numbers from the user

  num1 = getValue( MIN_VALUE, MAX_VALUE );
  num2 = getValue( MIN_VALUE, MAX_VALUE );
  num3 = getValue( MIN_VALUE, MAX_VALUE );
  num4 = getValue( MIN_VALUE, MAX_VALUE );

  //Find the smallest and largest numbers in the list

  lowNum = findLow( num1, num2, num3, num4 );
  highNum = findHigh( num1, num2, num3, num4 );

  //Calculate the sum, average and standard deviation of the numbers

  sum = calcSum( num1, num2, num3, num4 );
  avg = calcMean( num1, num2, num3, num4 );
  stdDev = calcStdDev( num1, num2, num3, num4 );

  //Display the numbers that were used in the calculations and the
  //results of the calculations

  cout << endl << endl << "The numbers that were entered: "
       << setw(5) << num1 << setw(5) << num2 << setw(5) << num3
       << setw(5) << num4
       << endl << "   Smallest:" << setw(20) << lowNum
       << endl << "   Largest:" << setw(21) << highNum
       << endl << "   Sum:" << setw(25) << sum
       << endl << "   Average:" << setw(21) << avg
       << endl << "   Standard Deviation:" << setw(10) << stdDev
       << endl << endl;

  //Ask the user if they have another set of numbers
  cout << "Again (Y/N)? ";
  cin >> again;
}

	return 0;
}

//Code the funtions below this line
int getValue( int lowerBound, int upperBound )
{
      
	cout << "Enter a value in the range (-100 - 100): ";
    cin >> Value;

	while (Value < -100.0 || Value > 100.0)
{
    cout << "Error: the value must be between -100 and 100. Try again: ";
    cin >> value;
}
      
}


	float findLow(float num1, float num2, float num3, float num4)
{
	float Low = num1;

	if (num2 < Low)
      Low = num2;
	if (num3 < Low)
      Low = num3;
   	if (num4 < Low)
      Low = num4;
	return Low;
}

	float findHigh(float num1, float num2, float num3, float num4)
{
	float High = num1;

	if (num2 > High)
      High = num2;
	if (num3 > High)
      High = num3;
   	if (num4 > High)
      High = num4;
	return High;
}


	float calcSum(float num1, float num2, float num3, float num4)
{
	return num1 + num2 + num3 + num4;
}


	float calcAverage(float num1, float num2, float num3, float num4)
{

   	float average = (num1 + num2 + num3 + num4) / 4;
   
   	return average;
}
closed account (1CfG1hU5)

i do not see a function for this prototype:

calcStdDev( num1, num2, num3, num4 );

which is assigned to stdDev

if this fixes for you, sorry do not have a paypal account to receive funds.
nice offer though.
i put the function in there but keep getting

"undefined reference to 'getValue(int,int)


im getting errors at

1
2
3
4
num1 = getValue( MIN_VALUE, MAX_VALUE );
num2 = getValue( MIN_VALUE, MAX_VALUE );
num3 = getValue( MIN_VALUE, MAX_VALUE );
num4 = getValue( MIN_VALUE, MAX_VALUE );



this part
I do not get those errors, but you do have problems with you getValue() function as it does not return a value and makes reference to identifiers "value" and "Value" which you have no defined.
1
2
3
4
5
6
7
8
9
10
11
int num1, num2, num3, num4 (int getValue)

      
	cout << "Enter a value in the range (-100 - 100): ";
    cin >> getValue;

	while (getValue < -100.0 || getValue > 100.0)
{
    cout << "Error: the value must be between -100 and 100. Try again: ";
    cin >> getValue;
}


changed too
Your syntax for adding the variable "getValue" is not correct. You are also still not returning anything in that code that I see.

Can you post the full updated code?
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

//Symbolic Constants

const int MIN_VALUE = -100;            //The smallest possible number
const int MAX_VALUE = 100;             //The largest possible number


int getValue( int lowerBound, int upperBound );
float findLow(float,float,float,float);
float findHigh(float,float,float,float);
float calcSum(float,float,float,float);
float calcMean(float,float,float,float);
float calcStdDev(float,float,float,float);


//Put the function prototypes here


int main()
{

/**********************************************************************
Variable Dictionary

num1, num2, num3, num4      The 4 numbers that are enteded by the user

sum                         The calculated sum

highNum, lowNum             The largest and smallest numbers

avg                         The calculated average

stdDev                      The calculated standard deviation

again                       The user's choice for continuation
**********************************************************************/

int num1, num2, num3, num4;
int sum, highNum, lowNum;
double avg, stdDev;

char again = 'Y';

cout << fixed << setprecision(3);


//While the user wants to perform calculations

	while( again == 'Y' or again == 'y' )
{

  //Get 4 numbers from the user

  num1 = getValue( MIN_VALUE, MAX_VALUE );
  num2 = getValue( MIN_VALUE, MAX_VALUE );
  num3 = getValue( MIN_VALUE, MAX_VALUE );
  num4 = getValue( MIN_VALUE, MAX_VALUE );

  //Find the smallest and largest numbers in the list

  lowNum = findLow( num1, num2, num3, num4 );
  highNum = findHigh( num1, num2, num3, num4 );

  //Calculate the sum, average and standard deviation of the numbers

  sum = calcSum( num1, num2, num3, num4 );
  avg = calcMean( num1, num2, num3, num4 );
  stdDev = calcStdDev( num1, num2, num3, num4 );

  //Display the numbers that were used in the calculations and the
  //results of the calculations

  cout << endl << endl << "The numbers that were entered: "
       << setw(5) << num1 << setw(5) << num2 << setw(5) << num3
       << setw(5) << num4
       << endl << "   Smallest:" << setw(20) << lowNum
       << endl << "   Largest:" << setw(21) << highNum
       << endl << "   Sum:" << setw(25) << sum
       << endl << "   Average:" << setw(21) << avg
       << endl << "   Standard Deviation:" << setw(10) << stdDev
       << endl << endl;

  //Ask the user if they have another set of numbers
  cout << "Again (Y/N)? ";
  cin >> again;
}

	return 0;
}

//Code the funtions below this line
	int num1, num2, num3, num4 (int getValue)

{     
	cout << "Enter a value in the range (-100 - 100): ";
    cin >> getValue;

	while (getValue < -100.0 || getValue > 100.0)
{
    cout << "Error: the value must be between -100 and 100. Try again: ";
    cin >> getValue;
}     
}

	float findLow(float num1, float num2, float num3, float num4)
{
	float Low = num1;

	if (num2 < Low)
      Low = num2;
	if (num3 < Low)
      Low = num3;
   	if (num4 < Low)
      Low = num4;
	return Low;
}

	float findHigh(float num1, float num2, float num3, float num4)
{
	float High = num1;

	if (num2 > High)
      High = num2;
	if (num3 > High)
      High = num3;
   	if (num4 > High)
      High = num4;
	return High;
}


	float calcSum(float num1, float num2, float num3, float num4)
{
	return num1 + num2 + num3 + num4;
}


	float calcMean(float num1, float num2, float num3, float num4)
{

   	float avg = (num1 + num2 + num3 + num4) / 4;
   
   	return avg;
}


	float calcStdDev (float num1, float num2, float num3, float num4)
{
	return ((num1 * num1)  +  (num2 * num2)  +  (num3 * num3)  +  (num4 * num4))-(((num1+num2+num3+num4)*(num1+num2+num3+num4))/4);
} 



only getting one error now " a function definition is not allowed here" in line 112
97: What is going on here? Is this supposed to be defining a function? It looks like you are declaring some variables or something.
97: float getValue (float num1, float num2, float num3, float num4)

tried that still no help
this is what its suppose to be
int getValue( int lowerBound, int upperBound )

Then use that. What errors do you get then?
Last edited on
something i have never seen before


http://tinypic.com/r/2mez9xd/8
If you have a function called getValue, you can't also have an identifier called getValue. Is that an issue you are having?
closed account (1CfG1hU5)
in first example, getValue() is storing to 4 integers, num1, num2, num3, num4, which stores to calcStdDev(), which stores to stdDev.

is there an overload issue?

this code on line 103 of both examples should be changed

while (getValue < -100.0 || getValue > 100.0)

you're looking for -100 or +100 maximum, so less than -100 or greater than 100 is wrong.

should be

while (getValue > -101 || getValue < 101) // .0 not necessary. not a float value

or

while (getValue >= -100 || getValue <= 100)

im just gunna turn this in for partial credit im fucked i have no idea
closed account (1CfG1hU5)
getValue() may not need any integer(s) passed.

should return the var "value" to main. also there are two variables named "Value" and "value" in getValue(). the var "value" is not defined in the function after the first brace.

put "int value;" in there and may fix

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int getValue()
{
  
  int value; // <--- add
    
    cout << "Enter a value in the range (-100 to 100): ";
    cin >> value;

	if (value <  MIN_VALUE || value > MAX_VALUE)  // better than while loop
{
    cout << "Error: the value must be between -100 and 100. Try again: ";
    cin >> value;
}

return value;
      
}

Last edited on
http://tinypic.com/r/9sfadd/8




You have a semicolon after the function on the line given; that shouldn't be there.
closed account (1CfG1hU5)
which line # has a semi-colon not needed?
im gunna have to find some1 else to help me. if u want payment even though we couldnt figure it out PM me
closed account (1CfG1hU5)
believe was close to fixing your code.

idea for num 1 through 4.

could do this inside while loop in main

1
2
3
4
int num[4], i;

for (i = 0; i < 4; i++)
   num[i] = getValue();


save a few lines of code
store each value from -100 to 100 in array elements and access by loops
Last edited on
Topic archived. No new replies allowed.