Question
Generate a program that asks a user for two integer inputs( in C++). The program will then determine if the first int is a factor
Generate a program that asks a user for two integer inputs( in C++). The program will then determine if the first int is a factor of the second. In math, a factor is simply a number that when multiplied by another can equal the third. For example, 2 x 3 = 6 so 2 and 3 are factors of 6. The number 32 has multiple factors. It could be 2 x 16, 4 x 8, 32 x 1. So, 1 is a factor of all numbers and a number is a factor of itself.
Here is an example of what your program output might look like.
Input the first integer:
2
Input the second integer
32
2 is a factor of 32.
Your program must handle the following errors.
- If the first integer is a zero, this will cause a divide by zero. So, throw an exception that outputs this error to the user.
- If the secod number is zero there is a problem. In mathmatics, zero has infinite factors. So, throw an exception stating that zero has infinite factors.
- The user may input something other than an integer. Handle this with a try catch block. Output to the screen that the user entered a non-integer value.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started