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;
}
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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.