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

HELP WITH C++ CODE Overview: Input two numbers, print out some conditional infor

ID: 3668312 • Letter: H

Question

HELP WITH C++ CODE Overview: Input two numbers, print out some conditional information about each number, then divide the numbers and show the result. After both numbers are entered, check whether the values are floating point or integer values. After this check, if a value is an integer, print out whether it is even or odd. Even or odd is not relevant for floating point numbers, so if it is floating point, simply print out that fact as the solution.o program does. Finally, if both number entered are integers, then do integer division and display a remainder. If either of the numbers has a decimal portion, then do floating point division and display one result. Note – in order to do input correctly, your initial input variables MUST be double. You must then check whether the value stored in that double type variable is in fact an integer value. After this check you can store that value in an integer variable, if applicable, but initial input from the user must be into a double. HERE IS HOW TO OUTPUT SOLUTION SHOULD LOOK:

Enter two numbers:23 12 First value is an integer First value is odd Second value is an integer Second value is even Integer Division Result is:1 with remainder:11

Explanation / Answer

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

bool double_is_int(double x) {
   double intpart;
   return modf(x, &intpart) == 0.0;
}

bool is_even(int x) {
   return x % 2 == 0;
}

int main() {
   ios::sync_with_stdio(false);
   cout << "Enter two numbers" << endl;
   double a, b;
   cin >> a >> b;
   if (double_is_int(a)) {

       cout << "First value is an integer" << endl;
       if (is_even(a))
           cout << "First value is even" << endl;
       else
           cout << "First value is odd" << endl;
   }
   else
       cout << "First value is a floating point" << endl;

   if (double_is_int(b)) {
       cout << "Second value is an integer" << endl;
       if (is_even(b))
           cout << "Second value is even" << endl;
       else
           cout << "Second value is odd" << endl;
   }
   else
       cout << "Second value is a floating point" << endl;

   if (double_is_int(a) && double_is_int(b)) {
       cout << "Integer Division Result is: " << ((int) a / (int) b) << " with remaindar: " << ((int) a% (int) b) << endl;
   }

   else {
       cout << "Floating division result is: " << a/b << endl;
   }

}