LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Can some one explain what I'm supposed to do in this assignment?? (https://www.linuxquestions.org/questions/linux-newbie-8/can-some-one-explain-what-im-supposed-to-do-in-this-assignment-4175428591/)

carlosk711 09-22-2012 08:41 PM

Can some one explain what I'm supposed to do in this assignment??
 
For this assignment you will modify the values of the arguments to a function in that function. I have provided you with a part of the main function below. Your task is to complete the main function and write the function fill. There are comments to guide you.
int main() {
int pi, e, gr;

fill(pi, e, gr);

/* Make sure that the numbers are assigned correctly and print them.
One way to do this is to set them to a default value and check it.
Determine how many numbers are assigned incorrectly,
and print the error message specified in the sample output. */

return 0;
}
This is what your output should look like.
Example 1:
Result:
pi = 3.14
e = 2.718
golden ratio: 1.618
Example 2:
Result:
Oops, something is wrong. Two of the numbers were assigned incorrectly.

much appreciated

PTrenholme 09-22-2012 08:57 PM

Can you explain what you don't understand? :scratch: The explanation provided by your instructor seems, to me, to be very clear.

carlosk711 09-22-2012 09:00 PM

I don't understand what we are supposed to do in general, can you explain it to me?? I'm just beginning so I don't understand what to do

carlosk711 09-22-2012 09:02 PM

what exctly is a fill command?

suicidaleggroll 09-22-2012 09:05 PM

Quote:

Originally Posted by carlosk711 (Post 4786862)
what exctly is a fill command?

As your instructor said in the instructions, it's just a dummy call to a function that you need to write.

carlosk711 09-22-2012 09:07 PM

so what does the function do? reads that out?
is there any cin's?

carlosk711 09-22-2012 09:09 PM

so basically, the users inputs the values of pi, e, and gr? the function then verfies if they are correct? and if they are it reads out the values they already entered?

PTrenholme 09-22-2012 10:44 PM

Quote:

Originally Posted by carlosk711 (Post 4786867)
so basically, the users inputs the values of pi, e, and gr? the function then verfies if they are correct? and if they are it reads out the values they already entered?

No, there's no "user input" involved. YOU, in the code you write, specify the values of the arguments. Then YOU write a fill function that verifies that you specified the values correctly.

You should probably consider an #include <math.h> in your code so you have the "real" values of M_PI and M_E available for use in your fill function. (The "golden ratio," (1+sqrt(5))/2, you'll need to compute yourself.) Oh, and a #include <stdio.h> so you can write out your answers.

Note: I'm ASSUMING (from what you posted) that this assignment is for C code, not C++ code.

rknichols 09-23-2012 08:25 AM

There are two things that make no sense at all in this assignment:

1. "you will modify the values of the arguments to a function in that function"
If the fill() function is doing the checking, why would it be modifying the values? If, as implied by the name, the fill() function is supposed to be filling in the values, then the way it is shown as being called from main() is wrong because the parameters are being passed by value and there is no way to pass the changes back to main().
2. The variables are declared as integer, but the values in the sample output are floating point.

I hope that whoever wrote that assignment is not that sloppy when writing code.


All times are GMT -5. The time now is 04:44 PM.