[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

C programming help

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 13
Thread images: 1

File: program.gif (16KB, 850x1100px) Image search: [Google]
program.gif
16KB, 850x1100px
I need help with my C programming HW due tomorrow ... I will attach the code I have so far in a file, but what I need to do is to create 3 functions. One to get the input for the numbers, one to take the average of those numbers added together, and one to print out the results. I have tried for hours to create the functions, but idk how to get the code from each function to work together to run the program. THANK YOUUUUUU
>>
Paypal me $10 and I will help you.
>>
>>301135
[email protected]
>>
Paypal me $10 and I will let you help me \(*_*)/
>>
Functions set up like this:

>One to get the input for the numbers
>void getNums(int * pArray){}
or if the number if ints isn't always 10, return the number of ints.
>int getNums(int * pArray){//return number of ints input}

>one to take the average of those numbers added together
>int aveNums(int * pArray){//return average}
or for a variable amount of numbers
>int aveNums(int * pArray, numOfNums){//return average}

>and one to print out the results.
>void printNums(int * pArray){}
or for a variable amount of numbers
>void aveNums(int * pArray, numOfNums){}

>how to get the code from each function to work together to run the program.
in main():
>getNums(pArray);
>int average = (pArray);
>printNums(pArray);
or if variable number of ints,
>int numOfInts = getNums(pArray);
>int average = aveNums(pArray, numOfInts);
>printNums(pArray, numOfInts);

optional for variable length array:
Instead of returning and using numOfInts for a variable length of ints, you could initialize the array to nulls then iterate through the ints until null is found.
>>
>>301151
>or if the number if ints isn't always 10, return the number of ints.
You're not going to be doing that: void means "doesn't return anything".
>>
>>301169
Try reading the very next line in that post.
>int getNums(int * pArray){//return number of ints input}
>>
>>301177
You're still being a retard, because all that's doing is generating extra object code, and duplicating source code. Copy/paste code is a classic place for weird bugs to hide in, and a function that behaves differently depending on what you do with its return value is the kind of thing you'd see in the Malicious C Contest.

C doesn't care if you ignore the return value, and doesn't care if you don't assign it to anything. You don't need a void version of an int function, and shouldn't use it unless the function genuinely never returns anything.

Adding a void version of an existing function is a horrifying misuse of polymorphism.
>>
>>301195
>Adding a void version of an existing function
>existing function
Where did you get that?
>or
one or the other depending on how anon was using it

>you're doing it wrong
>doesn't offer solutions
>>
>>301208
>doesn't offer solutions
As I said, always return an int and let the caller decide whether or not to ignore it.

Providing an additional function that returns a void just in case the caller doesn't use the return value is asinine.
>>
>>301208

OP: I need the code to function the way it does in the picture. I am using it to finish an example for my intro programming class.
>>
is this what you want?
>https://pastebin.com/8TrxRV4t


also, MODS code tag pwease
>>
>>301324
Yes thanks you so much :D
Thread posts: 13
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.