#How to implement a palindrome and number of vowels after function main?
20 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.
After the main function is where you would write the function definitions
Could you clarify your question? I'm not entirely sure what you are asking
For the love of humanity, why? 😢
Using just about everything C++ gives you, except for string.
wdym?
char str1[20]; // <<< this
cin >> str;
Listen, not your fault.
Teacher just gave you lemons, so make lemonade.
Yes, that's what I took from your screenshot.
Make no modifications to the existing code.
But add code underneath it all.
Lines 4 and 5 give you the prototypes for the functions that you must add.
If you compiled the code as-is you would get linker errors in relation to these two functions.
I really don't get it, I've been scheming other sources. Is this code provided involves recursion?
Nope
Basically function prototypes or declaration and function definitions are different.
Prototypes simply say "there is/will be a function with this name expecting these arguments return this type"
Function definitions actually determine what the functions does
The given code has the prototypes, now it is up to you to create the definitions
@copper meadow I will give a little example to hopefully help make the penny drop.
void printSomething(char* msg); // this is a prototype
int main()
{
printSomething("Nice to meet you");
return 0;
}
void printSomething(char* msg)
{
puts(msg);
}
Keep in mind that a compiler reads your code like you read a book; from top to bottom.
It does not jump around to find your stuff.
So when it comes a line in the code where a function is called, then that function must already be known to the compiler at that time.
If it is not then you will get a compiler error.
You have two choices:
- put that function in its entirety above main()
- forward declare (a.k.a. prototyping) the function ahead of main() and provide implementation after main().
Your teacher steers you towards (2) and has provided you with the partial implementation.
It's up to you to provide the implementation. You need to do this for two functions.
And yes; I am basically parroting what @short laurel just said (apologies).
This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.