problem with functions

I am new in programming

I am learning how to call functions

here is my function

#include <iostream>


using namespace std;
string name ()
{
cout << " write your name please? " << endl;
return 0 ;
}
int main()
{
cout << name () << endl;
return 0;
}


\\ the problem is that when ever i build my project it keeps crushing and foce closing

can someone help me ?

another question : if i dont write return in the function and then build it it will give me like a hundred symbol then it will crush
any one know why ?

The problem is that you declared the function as returning a string.
but instead you have return 0; which is an integer.

1
2
3
4
5
string name () // function return type is string
{
    string str = "example name";   
    return str; // actually return a string
}
Last edited on
Topic archived. No new replies allowed.