I have tried searching for previous posts about finding prime numbers, but I can't really seem to find any that can help me figure out how to impliment them into my code. So I thought I would post what I need help with, and what I have so far. Here it goes. This is only one step to my project, I hope to figure this out so I can do the other half on my own.
Write a program so that the user will enter two integers say x and y. As long as x>y, the program will print all primes between x and y inclusive. Also, write a function named findPrime which accepts two integer parameters say a and b. This function will print all prime numbers from a to b by calling the function isPrime. Have your program call this function busing the user input x and y.
My code:
CODE
// Project 4 IsPrime.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{ int x;
int y;
printf ( "Please enter two positive integers-->");
scanf ( "%d" "%d" , &x, &y );
printf ( "\nPRIME: ");
}
int findPrime ( int a, int b)
If 3 and 30 are entered for x and y, the program should produce the following output:
Prime: 3 5 7 11 13 17 19 23 29
(Prime count =9)
I'm not really sure where to start, not sure how to call isPrime to check to see if its prime or not, pretty sure I know how to write a code to figure out the prime number for 1 number, but not to list in between, just really confused, I know I need a for loop somewhere, and of course a while loop, I could really use help on how the program should look, (an algorithm would be nice). Well, any tips, pointers, or anything else would be greatly appreciated.
Adot2the~