error in program; extra symbol needed?

Here's the program:
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
#include <iostream>
#include <iomanip>

using namespace std;
#define LOWERRANGE -100.00
#define UPPERRANGE 100.00

void doRange(double);
double getReal(string, double, double);

int main()
{
	doRange(4);
	cout << endl << endl;
return 0;
}


double getReal(string prompt, double LOWERRANGE, double UPPERRANGE)
{
	double num6, num7, num8, num9;
	
	cout << "Enter the first real number: " << "(" << LOWERRANGE << "-" << UPPERRANGE << ")";
	cin >> num6;
	cout << "Enter the second real number: " << "(" << LOWERRANGE << "-" << UPPERRANGE << ")";
	cin >> num7;
	cout << "Enter the third real number: " << "(" << LOWERRANGE << "-" << UPPERRANGE << ")";
	cin >> num8;
	cout << "Enter the fourth real number: " << "(" << LOWERRANGE << "-" << UPPERRANGE << ")";
	cin >> num9;
	
	if(num6 < num7 && num6 < num8 && num6 < num9 && num7 > num8 && num7 > num9)   //num7 will be the largest number and num6 will be the smallest 
		{
			cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
			 	 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
			 	 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
			 	 << " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7 - num6;    //smallest number will be subtracted from the largest number
		}
		else if(num6 < num7 && num6 < num8 && num6 < num9 && num8 > num7 && num8 > num9)  //num8 will be the largest number and num6 will be the smallest
		{
			cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
			 	 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
			 	 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
			 	 << " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8 - num6;    
		}
		else if(num6 < num7 && num6 < num8 && num6 < num9 && num9 > num7 && num9 > num8)   //num9 will be the largest number and num6 will be the smallest
		{
			cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
				 << " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9 - num6;    
		}
		else if(num7 < num6 && num7 < num8 && num7 < num9 && num6 > num8 && num6 > num9)   //num6 will be the largest number and num7 will be the smallest
		{
			cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
				 << " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6 - num7;     
		}	   
		else if(num7 < num6 && num7 < num8 && num7 < num9 && num8 > num6 && num8 > num9)    //num8 will be the largst number and num7 will be the smallest 
		{
			cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
			 	 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
				 << " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8 - num7;     
		}
		else if(num7 < num6 && num7 < num8 && num7 < num9 && num9 > num6 && num9 > num8)   //num9 will be the largest number and num7 will be the smallest
		{
			cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
				 << " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9 - num7;       
		}  
		else if(num8 < num6 && num8 < num7 && num8 < num9 && num6 > num7 && num6 > num9)   //num6 will be the largest number and num8 will be the smallest
		{
			cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
			     << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
				 << " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6 - num8;      
		}
		else if(num8 < num6 && num8 < num7 && num8 < num9 && num7 > num6 && num7 > num9)   //num7 will be the largest number and num8 will be the smallest
		{
			cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
			     << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
				 << " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7 - num8;
		}	 	         
		else if(num8 < num6 && num8 < num7 && num8 < num9 && num9 > num6 && num9 > num7)   //num9 will be the largest number and num8 will be the smallest
		{
			cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
				 << " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9 - num8;    
		}  
		else if(num9 < num6 && num9 < num7 && num9 < num8 && num6 > num7 && num6 > num8)   //num6 will be the largest number and num9 will be the smallest
		{
			cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
			 	 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
				 << " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6 - num9;       
		}
		else if(num9 < num6 && num9 < num7 && num9 < num8 && num7 > num6 && num7 > num8)   //num7 will be the largest number and num9 will be the smallest
		{
			cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
				 << " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7 - num9;      
		}	
		else if(num9 < num6 && num9 < num7 && num9 < num8 && num8 > num6 && num8 > num7)    //num8 will be the largest number and num9 will be the smallest
		{
			cout << "The range of " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num6
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num7
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8
				 << " , " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num9
				 << " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << num8 - num9;
		}  
		
	return num6, num7, num8,num9;
}	 	 

when I go to build this program, it says "cpp:19: error: expected ',' or '...' before '-' token" I have no idea what is wrong
Line 19 reads as follows once your preprocessor macros are expanded:

double getReal(string prompt, double -100.00, double 100.00)

That's clearly wrong. You cannot use a constant where an identifier is required.
my teacher told us it should be something like this:
void doRange()
This function will perform the steps that are necessary to find and display the range of four double numbers. It should call the getReal() function four times to get the four double numbers, the four double numbers should be passed to the calcRange() function, and then the calculated range should be displayed.
double calcRange( double num1, double num2, double num3, double num4 )
This function will find the range of four double numbers. It takes four arguments: the four double values to find the range of; and returns the range of the values.
double getReal( string prompt, double lowerBound, double upperBound )
This function will get a double value from the user that is within a specified range. It takes three arguments: a string that will be part of the prompt that is displayed to the user, and two doubles that represent the lower and upper bound for a specified range. It returns a double value that is within the specified range.
The function should display a prompt to the user and accept a value. If the value is within the range, it should be returned to the calling function. If the value is invalid, display an error message and ask the user to to re-enter a value - this should be repeated until a valid value is entered.
I recommend you follow your teacher's instructions to the letter.
I have one more question. This is also part of the whole overall program as the program is above. This one is different than the one above.
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
#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;

#define LOWERM 1.00
#define UPPERM 100.00
#define LOWERN 1
#define UPPERN 100

void doPower(double, int);
double calcMtoN(double, double);

int main()
{
   doPower(1, 1);
   
return 0;
}

void doPower(double M, int N)
{
	double power;
	
	cout << "Enter the M value: " << "(" << LOWERM << "-" << UPPERM << ")";
	cin >> M;
	cout << "Enter the N value: " << "(" << LOWERN << "-" << UPPERN << ")";
	cin >> N;
	cout << endl;
	
	cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << M << " raised to the power of "
		 << N << " is " << setiosflags(ios::fixed | ios::showpoint) << setprecision(2) << power;		       
return;
}

double calcMtoN(double M, int N)
{
	double power;
	
	power = pow(M,N);
	
return power;	         
}	 	  

The only problem is I get 0.00 for the answer at the end and that's not the answer I want. I'm thinking its something within the double calcMtoN part
If you don't assign anything to power, of course it will contain garbage.
You seem to have an scope misunderstanding. This two power are different variables
1
2
3
4
5
6
7
8
9
void doPower(double M, int N){ //M, N you are coping the values, but you override them before use
// so why bother?
    double power;
//.....
} // here power dies
double calcMtoN(double M, int N){
	double power;
//...
}
Last edited on
Topic archived. No new replies allowed.