Question

1. Write a complete program in C++ that does the following: [2] asks a user to...

1.

Write a complete program in C++ that does the following:

  • [2] asks a user to enter two integer numbers (display a warning message that the second number should be different from zero)
  • [3] reads the two numbers from the keyboard;
  • [4] displays the product, the sum, the quotient and the remainder of integer division of the first one by the second one.

  • [3] displays the result of floating-point division.

Make sure to follow programming style guidelines.

Homework Answers

Answer #1

Solution: Following program has been given along with the output for the requirements. Comments have been added to depict the functionality.

#include <iostream>
using namespace std;

int main()
{
    //Create two integer variables
    int num1,num2;
    // Ask user for the first number
    cout<<"Enter the First Integer :  ";
    cin>>num1;
     // Ask user for the second number
    cout<<"Enter the Second Integer : ";
    cin>>num2;
    //Give warning to user if second number is 0
    //keep on asking the right input
    while (num2 == 0)
    {
        cout<<"second number should be different from zero, please enter again: ";
        cin>>num2;
    }

    //Print the different results
    cout<<"Product of the two numbers: "<<num1*num2<<endl;
    cout<<"Sum of the two numbers: "<<num1+num2<<endl;
    cout<<"Quotient : "<<num1/num2<<endl;
    cout<<"Remainder : "<<num1%num2<<endl;
    cout<<"Floating Point Division : "<<static_cast<double>(num1)/static_cast<double>(num2)<<endl;
    
}

Output:

Enter the First Integer : 13
Enter the Second Integer : 0
second number should be different from zero, please enter again: 4
Product of the two numbers: 52
Sum of the two numbers: 17
Quotient : 3
Remainder : 1
Floating Point Division : 3.25

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C program fractions.c that does the following: 1. The program starts by making the user enter...
C program fractions.c that does the following: 1. The program starts by making the user enter a non-negative integer number a, called the first numerator. If the user enters a negative number, the program repeats the entry. 2. The program then makes the user enter a positive integer number b, called the first denominator. If the user enters a non-positive number, the program repeats the entry. 3. The program then makes the user enter a non-negative integer number c, called...
Problems . Using the if...else if...else if......else, write a C++ program that - Asks the user...
Problems . Using the if...else if...else if......else, write a C++ program that - Asks the user to input two integers. - If both of them are greater than zero, then output their sum. - If only one integer is greater than zero, then output their difference. - Otherwise, output a message "your two number <0".
write a C++ program that asks the user to enter 4 integer numbers then use if...
write a C++ program that asks the user to enter 4 integer numbers then use if ….. elseif ….. elseif ….. else to find the smallest number then display it.
Write a program in C that does the following: Reads 10 real numbers from the keyboard...
Write a program in C that does the following: Reads 10 real numbers from the keyboard using a loop and displays the sum of the numbers and the sum of the square of the numbers.
Write a program that prompts the user to enter an integer number between 1 and 999....
Write a program that prompts the user to enter an integer number between 1 and 999. The program displays the sum of all digits in the integer if the input is valid; otherwise, it displays a message indicating that the integer is not between 1 and 999 and hence, is invalid. Name the program file Q1.cpp Example: if the user enters 12, sum of digits is 3. If the user enters 122, sum of digits is 5.
(SumDigits.java) Write code that asks the user to enter an integer between 100 and 999. The...
(SumDigits.java) Write code that asks the user to enter an integer between 100 and 999. The program finds and displays the three digits in the number. The program also calculates and displays the sum of the three digits. A sample run is shown below: Enter a number between 100 and 999: 528 The three digits in the number are: 5 2 8 The sum of the three digits is: 15 Note: You must use integer division and modulo division to...
Write a NASM program that does the following: 1) Asks the user to enter three numbers...
Write a NASM program that does the following: 1) Asks the user to enter three numbers (each is a byte) A,B, and C 2) Adds up the numbers and stores the sum in variable D 3) Outputs the sum
Write a program in C++ coding that asks the user to input an integer between 25...
Write a program in C++ coding that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2...
Write a C++ program that asks the user to enter in three numbers and displays the...
Write a C++ program that asks the user to enter in three numbers and displays the numbers in ascending order. If the three numbers are all the same the program should tell the user that all the numbers are equal and exits the program. Be sure to think about all the possible cases of three numbers. Be sure to test all possible paths. Sample Runs: NOTE: not all possible runs are shown below. Sample Run 1 Welcome to the order...
B.2. Write a Java program to display a dialog box that asks you to enter your...
B.2. Write a Java program to display a dialog box that asks you to enter your user name and the age as shown below: The program displays in a dialog box the sum of digits of your age. For example, if you age is 19, the sum will be 1+9 = 10 and the output will be as shown below: ( it just shows a message box that says the sum of the digits age of john is 10.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT