### "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.
=========================================================================

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 // includes #include #include #include #include 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.

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

 123 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.