• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++ question

FrogDog

Diamond Member
It's visual C++ 5 code (from a book), and I'm using a VC++ 6 compiler. That could be causing the errors, I don't know. Here's my code:

#include <iostream.h>

double addtwo(int x, double y);

int main(void)
{
int two = 2;
double number = 0;


cout << &quot;Choose a number.&quot; << endl;
cin >> number;

cout << endl
<< &quot;Your number plus 2 = &quot;
<< addtwo(int two, double number); <-----All three errors

cout << endl;

return 0;
}

double addtwo(double x, int y)
{
y += x;
return y;
}

The errors I get are these: 1) Syntax Error: missing ')' before type 'int'
2) 'addtwo' function does not take 0 parameters
3) Syntax Error: ')'

Little help?


 
First thing, when calling addtwo() don't include the variable types, just pass in the variables.

<< addtwo(int two, double number) //incorrect
<< addtwo(two, number); //correct

Also, addtwo() is declared to return a double, but you are returning y, which has been declared as an int.
 
Thanks. After I did that, it gave me weird errors that I didn't understand, but then I realized I had the double variable and a integer variable in the wrong spots in the function header. It works now. 🙂
 
additionally argument order also matters, if you declare routine foo(int x, double y), you should be passing integer type value followed by a double or in your case << addtwo(number, two);

 
Hehe. I'm suprised I actually got responces this quick in this forum. Usually my posts go unanswered or I have to bump it 3 times.

Thanks guys.
 
In your function prototype at the beginning, aren't you just supposed to lsit variable type? instead of declaring it too? before the main function.
 
Back
Top