- well the code you posted above doesn't really count as it is in effect a blank page on which to write. Usually we expect people to make a start in actually writing code, and then we will help when you encounter problems with what you have tried.
I started it out a bit for you.. You will have to go through and tweek some things, although i suggest retyping it so you can follow the logic. In particular, you'll need to account for the user inputting a negative number. Also, you will need to output the numbers it is divisible by. I also used a function, not sure if you have began using them yet.. If not, just let me know. Hope this helps!
#include <iostream>
usingnamespace std;
bool isPrime (int num); //function prototype
int main ()
{
int num=0;
cout << "Enter a number and I'll tell you whether it is prime: ";
cin >> num; //users input of the number being tested
if (isPrime(num)==true) //calling the function
cout << num << " is prime."; //outputing is prime
else
cout << num << " is NOT prime."; //outputting is not prime
return 0;
}
bool isPrime(int input) //function definition below
{
if(input<1) //automatically not prime
returnfalse;
elseif (input == 1||input ==2 ||input==3) //accounting for users input being 1,2, or 3
{ //which are automatically prime by definition
returntrue;
}
else
{
for(int i=2; i<input; i++) //running through an if loop to test if users input is divisible by
{ //i,w which is incrementing to test for user input values
if(input%i==0) //modulus division
returnfalse; //if not prime
}
returntrue; //if prime
}
}