1 Attachment(s)
Beginner need help with errors
Need help, errors messages added as comments after line.
#include <iostream>
int Add (int x, int y)
{
cout << "In Add(), received " << x << " and " << y << "\n"; //Error C2065: 'cout' : undeclared identifier
return (x+y);
}
int main()
using namespace std; //Error C2143: syntax error : missing ';' before 'using'
{ //Error C2447: '{' : missing function header
cout << "I'm in main()!\n";
int a, b, c;
cout << "Enter two numbers: ";
cin >> a;
cin >> b;
cout << "\nCalling Add()\n";
c=Add(a,b);
cout << "\nBack in main().\n";
cout << "c was set to " << c;
cout << "\nExiting...\n\n";
return 0;
-------------------------------------------------------
Another question,
What is code tags and how do use them?
Re: Beginner need help with errors
Please, replace this very bad made screenshot with an original code block (using Code tags of course!)
Re: Beginner need help with errors
First thing I see is that you are using cout in your Add function, but you haven't used the namespace yet.
Two ways to start is to change
Code:
int Add (int x, int y)
{
cout << "In Add(), received " << x << " and " << y << "\n"; //Error C2065: 'cout' : undeclared identifier
return (x+y);
}
to
Code:
int Add (int x, int y)
{
std::cout << "In Add(), received " << x << " and " << y << "\n"; //Error C2065: 'cout' : undeclared identifier
return (x+y);
}
or you can move
Code:
using namespace std; //Error C2143: syntax error : missing ';' before 'using'
just after the include
Code:
#include <iostream>
using namespace std; //Error C2143: syntax error : missing ';' before 'using'
Hope that helps.