"return" does not make the code to "return." =(

I keep having an error saying like this:
error C2059: syntax error : 'return'


I don't see how it is wrong, here's my source code I've created so far.
=========================================================================

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
// includes
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
	using namespace std;

// Function prototypes
double elasticityOfDemand(double, double);
double elasticityOfSupply(double, double);

// Start of main
int main(void)	{

	// Call a function to display my splash screen
	showIntro(4, 27, 2012, "Demonstration of void function");

	// Variables
	char userInput = 'a';
	double eD = -99.99;
	double eS = -99.99;
	double qD = -99.99;	// quantity demanded
	double pD = -99.99;	// price demanded
	double qS = -99.99;	// quantity supplied
	double pS = -99.99;	// price supplied

	// Prompt the user
	cout << "This program will help the user to get the price elasticity of demand, or that of supply." << endl;
	cout << "Please follow the direction correctly, and you will get the right value! =)" << endl;
	cout << endl << endl;



	do {
		cout << "Which of the price elasticity value would you like to get?" << endl;
		cout << "Type d for demand, or s for supply: " << endl;
		cin >> userInput;
		
		// Call the function
		eD = elasticityOfDemand(qD,pD);
		// Print the output
		cout << "When the percentage change in quantity demanded is " << qD << ", and that of price demanded is " << pD << ", " << endl;
		cout << "the price elasticity of demand is " << eD << ".";

		// Call the function
		eS = elasticityOfSupply(qS,pS);
		// Print the output
		cout << "When the percentage change in quantity supplied is " << qS << ", and that of price supplied is " << pS << ", " << endl;
		cout << "the price elasticity of supply is " << eS << ".";


	}
			

	return 0;
}

// Function definition

double elasticityOfDemand(double quantityDemanded, double priceDemanded)	{
	// While-loop
	while(userInput == 'd')	{
		double eDemand = -9.99;
		eDemand = quantityDemanded/priceDemanded;

	return eDemand;
	}
}

double elasticityOfSupply(double quantitySupplied, double priceSupplied)	{
	// While-loop
	While(userInput == 's')	{
		double eSupply = -9.99;
		eSupply = quantitySupplied/priceSupplied;

	return eSupply;
	}
}
Last edited on
It was nice of you to supply the full error message which included the line number.

On line 34 you begin what looks like you intended to be a do-while loop. There is no while() at the end of it.
Your code

do {
cout << "Which of the price elasticity value would you like to get?" << endl;
....
....
}

return 0;


is invalid because there is no such construction as do { /*...*/ } return 0; in C/C++
If I have to add while in the end of the do-loop, how should I put it?
Should it be like

1
2
3
do {
.........
} while(userInput == 'd' or 's');


this?? =(

I'm just so lost...

It is your program. I do not know what shall be there. But the construction

do { /*...*/ } while ( SomeExpression );

is valid in C/C++
Topic archived. No new replies allowed.