|
-
June 7th, 2008, 12:09 PM
#1
"return" error on function
Hi everyone,
I get the following error when I try to build my console program:
"error C2059: syntax error : 'return'"
#include <iostream>
#include <string>
using namespace std;
// Function Prototypes
double getValidValue(string question, double max, double min);
int main()
{
double loan = 0;
loan = getValidValue("Enter a loan amount", 10000000, 100);
}
double getValidValue(string question, double max, double min)
{
bool goodAnswer = false;
double answer = 0.0;
while(!goodAnswer);
do
{
cout << question << " (" << max << " <-> " << min << ") : ";
cin >> answer;
if (answer <= max && answer >= min)
{
goodAnswer = true;
}
}
return answer;
}
Thanks
-
June 7th, 2008, 12:15 PM
#2
Re: "return" error on function
You appear to have a do while loop without the while keyword. Also, note that the semi-colon after the while is probably unintended.
Also, properly indent your code and post it in [code][/code] bbcode tags.
-
June 7th, 2008, 12:18 PM
#3
Re: "return" error on function
 Originally Posted by jordantk
Code:
while(!goodAnswer);
do
{
...
}
return answer;
Look at the first line. The ";" ends the while loop. The "do" statement must be ended with "while" condition. You have "return" there - so this is your syntax error.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
June 7th, 2008, 12:21 PM
#4
Re: "return" error on function
Thats strange that you can't place the while before the do, I switched them around and no longer have the issue.
I got to remember this is C++ and not Java.
Thanks for the help!
-
June 7th, 2008, 12:30 PM
#5
Re: "return" error on function
Thats strange that you can't place the while before the do, I switched them around and no longer have the issue.
You can, but then it would be a separate while loop.
I got to remember this is C++ and not Java.
As far as I know, the C++ and Java syntax do not differ in this case.
-
June 7th, 2008, 12:36 PM
#6
Re: "return" error on function
 Originally Posted by jordantk
Thats strange that you can't place the while before the do...
Yes, you can. The "do" in that case is implied. And as noted above, you got an extra ";" in your while statement.
 Originally Posted by jordantk
I got to remember this is C++ and not Java.
That would help
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|