Can someone help me Im stuck and ive waited until the last minute.
Write and test a C++ program to perform the following sequence of events:
Create an array of 50 integer values.
Initialize the first element of the array to a value of 2 (the first prime number).
Use a function to examine a single number, determining whether it is prime or not by dividing it by all numbers from 2 to half the candidate value, looking for any divisions that have no remainder.
Generate the first 49 prime numbers after the number 2, and store them in consecutive values of the array.
Use a loop to display the contents of the array.
10pt BONUS - Use the previously-found primes as divisors to find the next prime.
10pt BONUS - Save the list of prime numbers to a file named primes.txt.
Format the file with one prime number per line.
What do you have so far? What exactly are you stuck on? You'll have to give us more info as this is not the type of forum where homework gets done for you - you'll need to show us you're putting in a majority of the effort. :)
That's all you can come up with on your own? If your current understanding of for loops is this weak, you need to go read about them again. Currently your i variable is doing absolutely nothing, and all your for loop is doing is setting the 2nd memory location in your "num" array to the value of 2. And that's it. That's all your code does at the moment. You're going to have to put in more than 2 minutes man.
I do not know if this correct for you. It works when I run the program. Check it for yourself,give me feedback and I will go and fix it for you mate. By the way your for loop look alright to me mate.
bool prime = true;
for(int i = 2; i < 50; i++)
if(i % num[i])
prime = false;
His for loop looks alright? His for loop does nothing but set the 2nd value of num to 2... How is that correct? While it's nice that the person somewhat understands how to write a very simple for loop (even though they don't seem to understand what it's doing...), they could have just scrapped the whole thing and typed num=2 instead. Even if he would have put i instead of 1, his for loop would only be setting every value in his array (except for the first two) to the number 2. Please explain how this is anywhere near correct. It's completely missing the actual logic (or even an attempt at the logic) that this homework assignment is designed to teach.
Please do not do people's homework for them if they're not willing to put forth more than a few minutes of effort. This forum exists to help people learn, and doing things for them without making them think at least a little bit on their own is not going to accomplish that goal.