Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'ve been trying different things but every time I think I solved it, whatever

ID: 3534889 • Letter: I

Question


I've been trying different things but every time I think I solved it, whatever number I pick, it says that it's still a prime number.


#include <iostream>

#define PROMPT "Please enter a whole number:"

#define NOT_PRIME "The number is not a prime number./n"

#define PRIME "The number is a prime number./n"

#define DONE 0 /* ends successful program */

#define FIRST_FACTOR 3 /* initial value in for loop */

using std::cout;

using std::cin;

int main(){

int i; /* loop counter */

char number; /* number provided by user */

cout << PROMPT; /* promt user */

cin >> number; /* wait for user input */

/* Prime numbers are defined as any number

* greater than one that is only divisible

* by one and itself. Dividing the number

* by two shortens the time it takes to

* complete. */

for(i = FIRST_FACTOR; i < number/2; ++i)

if( number/i == 0 ){ /* if divisible */

cout << NOT_PRIME << number; /* not prime */

return DONE; /* exit program */

}

/* if number is not divisible by anything

* than it must be prime */

cout << PRIME << number;

return 0; /* exit program */

}

Explanation / Answer

http://ideone.com/UFv5vJ

the changes are in line #

11 changed the data type of number to int

19 the condition should include equality

20 the condition you should be checking for is remainder to be 0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote