Using and Writing a function


#1

I am for some reason having a really difficult time with this in chapter 5. I just don’t seem to understand where to write all of this I guess. I am stuck on the part where it says " Open main. C in your ClassCertificates project and add a new function before the main function. Name this function congratulateStudent. I will post a screen shot of what it is I am talking about.

I was having so much fun with this book and doing it with ease and now I am stressing out big time on this chapter 5. I am sure its an easy fix and a user error by myself. Just wanna get back on track and keep reading this awesome book. Thanks for any help

and this is what I have. I know its for sure wrong.

Once again, thanks for any help and sorry if this is a simple fix


#2

You need to remove the congratulateStudent right before the start of int main…

You should have

void congratulateStudent(char *student, char *course, int numDays)
{
    printf("...your statement here...");
}
int main(ing argc, const char *argv[])
{
   congratulateStudent("Mark", "Cocoa", 5);
   // other congrat statements
}

I hope that helps get you going. Also, just FYI, in the future, the screen shot is great, but it helps if you cut & paste your code into your post between the code tags. That way we can cut & paste you code into our response with corrections instead of retyping… just sayin… :slight_smile:


#3

Thanks for the reply, Sorry about not pasting the code lol, I just saw that after I posted the screen shot. Will keep that in mind! And yes, that did help me out. I was sure it was something silly like that. None the less, thanks for the reply and helping me out :smiley:


#4

I think you are also missing a close-quote:


#5

Thanks for all the help, I have finally understood the function now :smiley:

I now have this and it runs

[code]#include <stdio.h>
#include <stdlib.h>

void congratulateStudent(char *student, char *course, int numDays)
{
printf("%s has done as much %s Programming as I could fit into %d days.\n",
student, course, numDays);
}

int main(int argc, const char * argv[])
{
congratulateStudent(“Mark”, “Cocoa”, 5);
sleep(2);
congratulateStudent(“Bo”, “Objective-C”, 2);
sleep(2);
congratulateStudent(“Mike”, “Python”, 5);
sleep(2);
congratulateStudent(“Ted”, “iOS”, 5);

return 0;

}

[/code]