Write the missing statements in the following program so that:
1. it prompts the user to input two numbers.
2. If one of the numbers is 0, the program should output a message indicating that both numbers must be nonzero.
3. If the first number is greater than the second number, it outputs the first number divided by the second number;
4. if the first number is less than the second number, it outputs the second number divided by the first number; otherwise, it outputs the product of the numbers.
C++ PROGRAM:#includeusing namespace std;int main(){ double firstNum, secondNum, thirdNum; double output; //missing statements return 0;}

Respuesta :

Answer:

The missing code for the above problem is as follows:

Explanation:

Missing code :

    cin>>firstNum>>secondNum; // for the first case.

    if(firstNum==0||secondNum==0) // for the second case.

    cout<<"Both the inputed numbers must be nonzero."; // for the second case.

    else if (firstNum>secondNum) // for the third case

    cout <<firstNum/secondNum; // for the third case.

    else if(secondNum>firstNum) // for the fourth case.

     cout <<secondNum/firstNum; // for the fourth case.

     else // for the fourth case.

     cout<<firstNum*secondNum; // for the forth case.

Output:

  • If the user input as 1 and 0, then the output is "Both the inputted numbers must be nonzero.",
  • If the user input is 4 and 2 then the output is 2.
  • If the user input is 2 and 4 then the output is 2.

Code Explanation:

  • The above code has to paste in the place of "Missing code" on the question program code.
  • All problem, which is defined in the question can be programmed by the help of the if-else statement.
  • The compiler first checks the if condition and then it checks the else-if and then else if the above condition is false.