I made a simple program, and it won't compile. Here's the program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
usingnamespace std;
int returnthis (int a; int b;) {
return a + b;
}
int main ()
{
int returnedint, a, b;
cout << "Enter a number: \n";
cin >> a;
cout << "Enter a number: \n";
cin >> b;
returnedint = returnthis(a,b);
cout << "Returned value: " << returnedint;
return;
}
When I try to build in MS visual C++ express, I get the following errors:
1>MyFirstCplusplusFunction.cpp(2): warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1> Add directive to 'StdAfx.h' or rebuild precompiled header
1>MyFirstCplusplusFunction.cpp(21): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
Click the "project" tab on the tool bar and go to properties. Under configuration properties, go to C/C++ and click on "Precompiled headers". Click the drop down box beside "Precompiled header" and select "Not using precompiled headers".
When creating a project, make sure you un-check precompiled headers in the wizard.
Remove the semi-colon from the parameters of your function:
int returnthis (int a; int b;)
Should be:
int returnthis (int a, int b)
Notice the comma? Commas are used to seperate arguments in function parameters.
Obviously edited after someone else posted, but since this post is posted ahead of the other one, people will think I figured it out despite the fact that it states that it's quoting L B:
L B wrote:
Also, main must return a value - on line 17 you are returning nothing (void).