Basic Function Help

Ok complete novice attempting to understand functions so please no bashing. I am attempting to create a simply function call from main in which the function itself will ask for the membership type from the user and then return that answer to main....but it's not working someone please explain to me what I am missing and how to fix it.




using namespace std;

char Get_Member_Type (char);

int main()
{
char Member_Type;
Member_Type = Get_Member_Type();
}

char Get_Member_Type ()

{
char Member_Type;
cout << " Enter your membership type followed by return. 'I' for Individual and 'F' for Family ";
cin >> Member_Type;
return Member_Type;
}
Well, just some pointers for your next thread:
- Use blocks for your code
- indent
- post error codes
- you dont have to tell us no bashing lol this community is really kind for the most part

As for you code,
-Your forgot to #include <iostream>
-in your function prototype there should be a char in the parameters. just char Get_Member_Type();
- main should return 0 at the end
- IDK if what you have is correct, but delete the empty line between the function name and its body

There might be other stuff im missing, but try that and post error codes if it still doesnt work!
Thank you for the quick response, I am not sure what you mean by blocks....
I did get it working after I remove char from the prototype and added the return so thank you.
Can you explain why the return 0 was so important? and whar the char wasn't needed in the prototype?
char Get_Member_Type ()
<--- this looks ugly is what he meant i think :P
{
char Member_Type;
cout << " Enter your membership type followed by return. 'I' for Individual and 'F' for Family ";
cin >> Member_Type;
return Member_Type;
}

char Get_Member_Type (char);
the char inside the parenthesis isnt needed because stuff inside parenthesis are parameters. for example
1
2
3
4
char increase(char character)
{
    return character+1;
}

to call this function you would say:
char useless = increase('a'); where useless would be 'b' after that.

main should return 0 in the end just to signify that the program exited naturally, not because of an error
Last edited on
Nelli wrote:
I am not sure what you mean by blocks....
He means surround your code with these tags [code][/code]. So:

[code]//your code[/code]

becomes:

//your code
Topic archived. No new replies allowed.