I studied C++
for a long time and now I need to help a friend. Bug and code included.
Yuzayu cpp.sh
:
// Example program
#include & lt; iostream & gt;
#include & lt; string & gt;
#include & lt; cmath & gt;
# include & lt; math.h & gt;
using namespace std;
int main ()
{
/ * std :: string name;
std :: cout & lt; & lt; "What is your name?";
getline (std :: cin, name);
std :: cout & lt; & lt; "Hello," & lt; & lt; name & lt; & lt; "! \ n";
std :: cout & lt; & lt; "KAPEZ"; * /
float sqr (float fl1, float fl2) {
// float s = (fl1 * fl2) / 2;
return (fl1 * fl2) / 2;
};
// std :: cout & lt; & lt; sqr (2, 3)
}
Error:
In function ‘int main ()’: 16:35: error: a function-definition is not allowed here before ‘{‘ token
Answer 1, authority 100%
Move your sqr
outside of main
– you can’t nest functions in C++.
# include & lt; iostream & gt;
#include & lt; string & gt;
#include & lt; cmath & gt;
# include & lt; math.h & gt;
using namespace std;
float sqr (float fl1, float fl2) {
// float s = (fl1 * fl2) / 2;
return (fl1 * fl2) / 2;
};
int main ()
{
std :: string name;
std :: cout & lt; & lt; "What is your name?";
getline (std :: cin, name);
std :: cout & lt; & lt; "Hello," & lt; & lt; name & lt; & lt; "! \ n";
std :: cout & lt; & lt; "KAPEZ";
std :: cout & lt; & lt; sqr (2, 3);
}