Hey again I need a little help with this assignment. What I'm supposed to do is have a user enter a positive integer and then the program should tell the user all the prime numbers before the number the user entered. However, with my program when I enter 22 for example it will give me numbers like 25, 26, and 28, or something along those lines.
Here's my code:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
int choice;
cout<<"What would you like to do: "<<endl;
cout<<"Make your choice by entering 1, 2, 3, or 4 "<<endl;
cout<<"+-------------------------------+"<<endl;
cout<<"1. Enter a positive integer, then print out all the prime numbers that are less than or equal to the number you entered"<<endl;
cout<<"2. Enter a positive integer and then print out the number with its digits reversed"<<endl;
cout<<"3. Enter two positive integers and then print out the greatest common factor"<<endl;
cout<<"4. Nothing"<<endl;
cout<<"+-------------------------------+"<<endl;
cin>>choice;
if(choice==1)
{
int n=0;
cout<<"Please enter a positive integer "<<endl;
cin>>n;
while( n > 1)
{
if( n % 2 != 0, n % 3 != 0)
{
cout<<"The prime numbers are: "<<n<<endl;
n++;
if(n % 6 == 0)
{
n++;
}
}
}
}
Thanks again for the help