XCode 4 C++ Question

Discussion in 'Mac Programming' started by mgoff121, Aug 29, 2011.

  1. mgoff121 macrumors newbie

    Joined:
    Aug 29, 2011
    #1
    I am having problems with the console window reading input. As an example, when I run the program below, the console window will ask for the width only. The program will continue running indefinitely and never ask for the length. Please advise. When I run the program from the terminal, there are no problems.

    #include <iostream>
    using namespace std;

    int main(){
    double width,length;
    cout << "Enter width of rectangle ";
    cin >> width;
    cout << "Enter length of rectangle ";
    cin >>length;
    cout << " Area is " << width*length << endl;
    }

    Thanks for the help!
     
  2. drsoong macrumors member

    Joined:
    Mar 24, 2008
    Location:
    Munich
    #2
    The code you posted works fine, when I compiled and executed it in the terminal.

    Are you building and running it in XCode? - Though that shouldn't make a difference. Is this really the code you have in the source file (copy-and-pasted)?
     
  3. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #3
    Under XCode 4.2 (beta), I can't replicate your problem.

    I do remember people complaining about the console not behaving correctly in earlier versions, maybe even before XCode 4.

    If XCode isn't working out for you with C++, perhaps try Eclipse.
     
  4. mgoff121 thread starter macrumors newbie

    Joined:
    Aug 29, 2011
    #4
    Yes I am building and running it in Xcode version 4.1. This is the exact code I have in the source file. I know the code works, because I can run it directly from the terminal with no problems.
     
  5. drsoong macrumors member

    Joined:
    Mar 24, 2008
    Location:
    Munich
    #5
    Ok. Sorry, I missed that part in your original post.

    On Snow Leopard it seems I am stuck with XCode 4.0.2. :-(
     

Share This Page