Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Help- practice using loops and if statements. I need to write a prime test program. In order to check if a number is prime,

C++ Help- practice using loops and if statements. I need to write a prime test program. In order to check if a number is prime, use a loop to try dividing the users number by each number between 2 and the number provided. If any of the numbers between 2 and the users number divides their number, then it is not prime. If none of the numbers divides their number, then it is prime. Do not bother dividing the users number by itself since that will always give 1. I have this so far:

#include  using namespace std; int main() { int usrNumber; bool isPrime = true; cout << "============PRIME TESTER============" << endl; cout << "What number would you like to test? > "; cin >> usrNumber; // Implement a prime test here. return 0; } 

*Expected Output 1 (user input in italics)

============PRIME TESTER============

What number would you like to test? > 1

The number 1 is neither Prime nor Composite.

*Expected Output 2

============PRIME TESTER============

What number would you like to test? > 11

The number 11 is Prime.

*Expected Output 3

============PRIME TESTER============

What number would you like to test? > 4

The number 4 is not prime.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions