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
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...
In C++ write a program for a multiplication table It must Prompt the user for two...
In C++ write a program for a multiplication table It must Prompt the user for two integers between 1 and 20 (inclusive) • also must Calculates and displays the multiplication table in a well-formatted output The table must include a label for each row and column The program must follow the requirements: • Validates user input, displaying an error message and prompting to user to enter another integer if the input is invalid, and repeating it as many times as...
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.
Write a program that asks the user to input an integer between 25 and 50, inclusive....
Write a program 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 relational expressions. You...
Q :     Write a C++ program that asks the user to enter three integers and...
Q :     Write a C++ program that asks the user to enter three integers and then displays the largest one. Example : if the user enter ( 7, 2 ,5) the largest number will be 7 Or if user enter ( 2 , 5 , 7 ) the largest number will be 7 Or if user enter ( 7, 5 ,2) the largest number will be 7 In general it does not matter the order of the entered numbers...
problem 1 Write a program that asks the user for an integer and then prints out...
problem 1 Write a program that asks the user for an integer and then prints out all its factors. For example, when the user enters 84, the program should print 2 2 3 7 Validate the input to make sure that it is not a character or a string using do loop. in c plus plus
Write a program that asks the user to enter two integer numbers. the main function then...
Write a program that asks the user to enter two integer numbers. the main function then passes these numbers to a function named exp that calculates the multiplication of these numbers and print the exponential value of the result of multiplication
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT