Question: This is for C++ programming. It's not for Java. A prime number (or a prime) is a whole number greater than 1 that has no
This is for C++ programming. It's not for Java.
A prime number (or a prime) is a whole number greater than 1 that has no positive divisors other than 1 and itself. Write a program that determines if a number is prime by defining and using the following functions: getPositiveWholeNumber: This function asks the user for a positive whole number (integer) repeatedly until the input is correct. You can assume that the user will only input whole numbers, but you need to check if they are positive. isPrime: This function takes an integer as a parameter and returns a bool. The function returns true if the parameter is a prime number, otherwise, the function returns false. The function should first check if the number is 1, 0, or negative; these values indicate the number is NOT prime (return false). For any other value, the function should use a for loop to test if there are any devisors of the number that do not result in a reminder. If no such devisors are found, the number is prime. Note that any divisor greater than half the number must have a remainder. This function should not get any input from the user or display any information (i.e., do not use cin or cout). displayNumberInfo: This is a void function that accepts a single integer as a parameter. The function should output the number followed by "is a prime number" or "is not a prime number" depending on what is returned by calling isPrime. Your main function should only call getPositiveWholeNumber and displayNumberInfo. Also, it can define any variables that are necessary.
This is for C++ programming. It's not for Java.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
