The highest Mersenne Prime? (hw part 2)

Ok, so now I am on part 2 of my homework and I believe I need to use an array in order to solve the second part. But, we have yet to cover arrays in class and I am unsure on how to accomplish this. Ive put in some aspects of an array but Im not sure if I did it right.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  #include<iostream>

using namespace std;

int main()
{
	int x, y,z, count = -1;
	int *array = new int[0];
	bool prime = true;
	cout << "What is the total number of prime numbers?!.\n";
	cout << "Please enter a number.\n";
	cin >> x;
	for (z = 2; z <= x - 1;z++)
	{	
		bool prime = true;
		for (y = 3; y <= z-1; y++)
		{
			if (z%y == 0)
			{
				prime = false;
				break;
			}
		}
		if (prime) count++;
	}
	for (z = 2; z <= x - 1; z++)
	{
		bool prime = true;
		int *array = new int[x];
		for (y = 3; y <= z - 1; y++)
		{
			if (z%y == 0)
			{
				prime = false;
				break;
			}
		}
		if (prime)
		{
			(z + 1);
			(z % 2 == 0);
			cout << "The highest Mersenne Prime is\n" << z << endl;
		}
	}
	cout << "The total number of prime numbers less than\n" << x << " "<< "is" <<" "<< count<< endl;
	delete[] array;
	return 0;
}


I get the right number of Mersenne Primes but I need it to only print out the highest one.


You don't need an array.

Line 42: Instead of cout the prime each time store z in another variable (like max_prime), move line 42 after line 44 and cout max_prime instead of z.
Wow got it in 5secs...... thanks for the tip!
Topic archived. No new replies allowed.