So I'm new at all of this programming jazz and I could really use some help. The assignment has already been turned in, I would just like to figure this out before we move in class. Teacher isn't in town so I can't ask him for the moment. Could really use your help. Thanks.
So this is the assignment...
A prime number is a number greater than 1 which is only evenly divisible by 1 and itself. For this assignment you will find which numbers from 2 to n (where n is a user-specified number) are prime.
Ask the user for a number, n, greater than 2. Keep asking for a number until a number greater than 2 is provided. Assume that the user will only enter numbers (that is, you do not need to check if a user enters text).
Use a loop to iterate on a variable, i, from 2 through n. For each iteration, check all numbers from 2 through i to determine whether the number is prime. If it is prime, print out i and the word "Prime".
Use the modulus operator, %, to determine if a number is prime
Example output:
Please enter a number larger than two: -939
Please enter a number larger than two: 2
Please enter a number larger than two: 20
2 Prime
3 Prime
5 Prime
7 Prime
11 Prime
13 Prime
17 Prime
19 Prime
This is what I have so far. I suppose i'm not really understanding how to continue with the second for loop. The first one just prints out a list of numbers from 2 to the number designated by the user. In my case that variable is user_input.
Code:// Alen // Prime // # include <iostream> using namespace std; int main() { int user_input; int i; int n = 1; int total=2; do { cout << "Enter a number greater than 2." << endl; cin >> user_input; } while (user_input<=2); for (i=2; i < user_input; i++) { } return 0; }