Help with C function coding Im 50 sure I cant really underst

Help with C++ function coding! I\'m 50% sure (I can\'t really understand the question) that it wants me to just have the function have 3 arguments check(int x, double y, double z) and have like 3 numbers be called by this function \"check\" so that x should be an interger if I type 4.5 (it should spit out 4) and if it type 2 and 3 for y and z (respectively), it should spit out 2.0 and 3.0 since they are doubles? I wasn\'t sure if I needed to use if/else within the function and how to actually display the check numbers in the body of the main (using cout ???). Here is the question below and my code:

#include <iostream>
#include <cmath>
using namespace std;
int check(int, double, double);

int main()
{
   int firstnum = 3.5;
   double secnum= 2;
   double thirdnum= 2;

   temp = check(firstnum, secnum, thirdnum);
   cout << temp;
   system(\"pause\");
       return 0;
}
int check(int i, double d, double dd)
{
   int matrix = i;
   double matrix = d;
   double matrix = dd;

   return matrix;
}

a) Write a function named check that has three arguments. The first argument should accept an integer number, the second argument a double precison number and the third argument a double precision number. The body of the function should just display the values of the data passed to the function when it is called. (Note: When tracking errors in functions, it is helpful to have the function display the values it has been passed.) b) Include the function check in a working program. Make sure your function is called from main Test the function by passing various data to it.

Solution

C++ code:

#include <iostream>
#include <cmath>
using namespace std;

void check(int i, double d, double dd)
{
cout << \"I = \" << i << endl;
cout << \"d1 = \" << d << endl;
cout << \"d2 = \" << dd << endl;
}

int main()
{
int firstnum = 3.5;
double secnum= 2;
double thirdnum= 2;
check(firstnum, secnum, thirdnum);
return 0;
}

Sample Output:

For  int firstnum = 3.5; double secnum= 2; double thirdnum= 2;

I = 3
d1 = 2
d2 = 2

Yes your guess is correct, if you pass x = 4.5 (it should spit out 4) and if it type 2 and 3 for y and z (respectively), it should spit out 2.0 and 3.0 since they are doubles.

Help with C++ function coding! I\'m 50% sure (I can\'t really understand the question) that it wants me to just have the function have 3 arguments check(int x,
Help with C++ function coding! I\'m 50% sure (I can\'t really understand the question) that it wants me to just have the function have 3 arguments check(int x,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site