Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

  1. 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.
  2. 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.
  3. 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

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions