0
#include <stdio.h>
#include <cs50.h>
int main(void)
{
long creditcardno;
do
{
creditcardno = 
get_long("enter");
}
while (creditcardno <  0);
}

The above code accepts positive integers while taking input for credit card no.

The task is now to form a function my_function () that will perform the above task when called in the main function.

All that I can figure out is:

include <stdio.h>
#include <cs50.h>
long my_function (void);

Will the next line include int main (void) or that will not appear at all.

Is it possible that I form a different c file such as test.c that will include function definition only and this file be called in main function in credit.c. Or both possibilities are there. I can have function defined and called in the same file so that everything can be performed from credit.c file.

0
1

The structure is simple. Pay attention to placement of curly braces and semicolons, specifically, where they are NOT.

#include statements

// The next line is a function signature to tell the compiler that
// the actual function will follow later.  You either need a signature 
// or the actual function to appear before it is ever used anywhere. 
// note the semicolon here, but not in the similar line at the function. 

int myfunction(<empty or var declarations go here>); 


int main (void)
{
    // main code goes in here
}


int myfunction(<empty or var declarations go here>)
{
    // function code goes in here
}

That's all there is to it.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .