#include <iostream>
//This will create a function that prints 'You just called a function.'
void function()
{
std::cout << "You just called a function.\n";
}
//This will use a function allong side 'std::cout' to print text on the screen.
int main()
{
function();
std::cout << "Really? :O";
<< Add(10+13);
}
// This will add two specified numbers.
int Add (int x, int y)
{
return (x+y);
}
Please could someone explain why this is not working and how to fix it?
Thanks.
1)Add should be declared before it is used (used on line 14 and declared on 18). You can either move the whole function definition before the main or keep it in its place and add a prototype before main (int Add(int x, int y);).
2) On line 14, you probably forgot something before the << operator. Perhaps you wanted to print the output? It should be something like std::cout << Add(10, 13);.
<< is a binary operator. What is on the left side of << on line 14? ';' ?
Add is a function that takes two arguments, while you only pass one. write Add(10, 13) instead.
The compiler reads your code from top to bottom. On line 14 it has no knowledge of a function you define on line 18. You should declare the function Add before you call it.