Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
I see. Thanks. I now have the following, which seems to do the job.

Code:
#include <iostream>
using namespace std;

// print out the primes smaller than the user's chosen number

int main ()
{
  int n, ii;
  cout << "Enter a number between 1 and 1000: ";
  cin >> n;
  if (n > 2) {
    cout << "2";
    for (int i = 3; i < n; i++) {
      for (ii = 2; ii <= i/2; ii++) {
        if (i % ii == 0) break;
      }
      if (ii == i/2 + 1) cout << ", " << i;
    }
  cout << "\n";
  }
  return 0;
}
 
Dear All,

How do I tell terminal where to look when I want to compile a project? As things stand, it seems only to look the section of the drive with stuff like Desktop, Library, and Documents in it). Now I've moved my .cpp files into a sub-folder, it can't find them. Is there anything I can do about this?
 
Dear All,

How do I tell terminal where to look when I want to compile a project? As things stand, it seems only to look the section of the drive with stuff like Desktop, Library, and Documents in it). Now I've moved my .cpp files into a sub-folder, it can't find them. Is there anything I can do about this?
Code:
cd ~/Documents/Code

It will look in the current working directory, so all you need to do is change directory (cd) to the folder you want it to look for your code in, say ~/Documents/Code

(~ is shorthand for your home folder /users/<user> where <user> is your username)

Or, you can explicitly tell it where to look and where to put stuff
Code:
g++ ~/Documents/Code/foo.cpp -o ~/Documents/Code/bar

For more complicated projects, there are environment variables a plenty for you to control how things are found and in what order, but you're not there yet.

B
 
Great. Thanks again. That does the job.

For more complicated projects, there are environment variables a plenty for you to control how things are found and in what order, but you're not there yet.

Right!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.