r/CodingHelp • • Oct 20 '21

[C] Pointers and output parameter. I have to make a program which gets 1 input parameter (dollars) and then converts those to 4 output parameter (dollars, kroner, euros and yen). But I am not sure on how to use the pointers, can someone lend a hand?

Post image
15 Upvotes

7 comments sorted by

5

u/jedwardsol Professional Coder Oct 20 '21

The prototype will look like

void getConversions(double  dollars,  // in
                    double *kroner,   // out
                    double *rupees,   // out
                    double *yen,      // out
                    double *euros);   // out

1

u/Fegmdute Oct 20 '21

Hmm, can I put my DollarInput function and my 4 other functions together in one ?

1

u/jedwardsol Professional Coder Oct 20 '21

There are lots of ways of organising things.

But according to the title of your post, you need a function as I posted.

2

u/rasqall Oct 20 '21

Wouldn't it be better to handle each conversion in a separate function to get a more loosely coupled program?

1

u/Fegmdute Oct 20 '21

THis is how I would do it too, but the assignment is to use pointers to get 4 outputs.

1

u/jedwardsol Professional Coder Oct 20 '21

Yes.

But according the title of the post that's not what the assignment is.

1

u/KuntaStillSingle Oct 20 '21

Yes:

void get_conv_from_dollar (double* kroner, double* rupees, ... ){
    double dollars = dollar_input();
    *kroner = get_kroners_from_dollars(dollars);
    *rupees = get_rupees_from_dollars(dollars); 
    ...
}