This is just my pseudocode, but I'm having trouble with one portion.
//module prototype
Boolean isPrime(int number)
main ()
[int number
display we are going to see if the positive integer you enter is a prime number or not
do
[
display enter a positive number
input number
trueOrFalse=isPrime(number)
if (trueOrFalse == true)
[the number is prime]
else
[the number is not prime]
]
bool isPrime(int number)
[
bool status
if (number%2==0)
[status=true]
if(number%3==0_
[status=true]
else
[status==false]
return status
]
if (number%2==0)
[status=false]
if(number%3==0_
[status=false]
This is the portion I'm having trouble with.
While I'm pretty okay with how to set my program up, I'm not too sure how to calculate if a number is prime or not int the actual code although I do know what a prime number is.
I figured if it gives a remainder or 0 if it's divided by 2 or 3 the number would not be prime, but I don't believe that'll work.
get number
while(the counter is not equal to number/2)
{
check for prime
if prime is true
get out of loop and print its prime
else
increment the counter
}
if the prime is not true
print the number is not prime
int main()
{
int number;
string keepGoing;
bool trueOrFalse;
cout << "We are going to see if the positive integer you enter is a prime number or not." << endl;
do
{
cout << "Enter a positive number." << endl;
cin >> number;
trueOrFalse=isPrime(number);
if (trueOrFalse==true);
{
cout << "The number is prime." << endl;
}
if (trueOrFalse==false);
{
cout << "The number is not prime." << endl;
}
cout << "Would you like to see if another number is prime? Type yes if so." << endl;
}
while (keepGoing=="yes");
#include <iostream>
#include <string>
usingnamespace std;
//module prototype
bool isPrime (int number);
int main()
{
int number;
string keepGoing;
bool trueOrFalse;
cout << "We are going to see if the positive integer you enter is a prime number or not." << endl;
do
{
cout << "Enter a positive number." << endl;
cin >> number;
trueOrFalse=isPrime(number);
if (trueOrFalse==true);
{
cout << "The number is prime." << endl;
}
if (trueOrFalse==false);
{
cout << "The number is not prime." << endl;
}
cout << "Would you like to see if another number is prime? Type yes if so." << endl;
}
while (keepGoing=="yes");
//there should be a bracket here
bool isPrime(int number)
{
counter = 2//initialize it as int
//---------------------------------this whole section is logically flawed----------------
while(counter<number)
{
if (number%counter==0)
{
returnfalse//semicolon?
}
else
{
returntrue//semicolon
}
}
//---------------------------------this whole section is logically flawed----------------
}
return 0;//returning 0 is not a good idea
}
http://prntscr.com/boht1w
This is the code I have now (it indented for me so tell me if my indents are wrong)
#include <iostream>
#include <string>
usingnamespace std;
//module prototype
bool isPrime (int number);
int main()
{
int number;
string keepGoing;
bool trueOrFalse;
cout << "We are going to see if the positive integer you enter is a prime number or not." << endl;
do
{
cout << "Enter a positive number." << endl;
cin >> number;
trueOrFalse=isPrime(number);
if (trueOrFalse==true);
{
cout << "The number is prime." << endl;
}
if (trueOrFalse==false);
{
cout << "The number is not prime." << endl;
}
cout << "Would you like to see if another number is prime? Type yes if so." << endl;
}
while (keepGoing=="yes");
bool isPrime(int number)
{
int counter = 2
while(counter<number)
{
if (number%counter==0)
returnfalse;
elsereturntrue;
}
}
return 0;
}
Hey FB, you're asking about pseudocode and demand people correct it for you.
Your first step is to actually write pseudocode. What you have so far presented is nothing like it. I suggest you go back and revise your notes/text, see a tutor/prof. At present unfortunately you are just spinning your wheels :)
As a tip visit Wikipedia on primes. There is ample material there on pseudocode and primes, individually and combined. Come back by all means when you have something we can all call pseudocode . :)
Actually, we're fixing my real code now. Didn't you see? Haha. :)
Anyways, I fixed the errors, but it's giving me this output. How do I fix it? It keeps saying the number is and isn't prime and when I try to type yes to enter another number it won't let me. http://prntscr.com/bohzf6
#include <iostream>
#include <string>
usingnamespace std;
//module prototype
bool isPrime (int number);
int main()
{
int number;
string keepGoing;
bool trueOrFalse;
cout << "We are going to see if the positive integer you enter is a prime number or not." << endl;
do
{
cout << "Enter a positive number." << endl;
cin >> number;
trueOrFalse=isPrime(number);
if (trueOrFalse==true);
{
cout << "The number is prime." << endl;
}
if (trueOrFalse==false);
{
cout << "The number is not prime." << endl;
}
cout << "Would you like to see if another number is prime? Type yes if so." << endl;
}
while (keepGoing=="yes");
}
bool isPrime(int number)
{
int counter = 2;
while(counter<number)
{
if (number%counter==0)
returnfalse;
elsereturntrue;
}
return 0;
}
firstly you are not incrementing counter, and like I said before your isprime function is faulty, I have given you pseudo-code beofre, try to understand it and edit your code
What do I mean? You're joking right? Use the same tag system you've used on all your other numerous threads where you expect people to do your homework for you.