Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help with C++ function coding! I\'m 50% sure (I can\'t really understand the que

ID: 3791231 • Letter: H

Question

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.

Explanation / Answer

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.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote