Help with command line tool on xcode!

Discussion in 'Mac Programming' started by noahgolm, Aug 19, 2010.

  1. noahgolm macrumors member

    Aug 18, 2010
    I am just starting xcode, and am fiddling with basic c, such as performing algebraic math equations. I already wrote a program which runs in terminal and shows conversion between Fahrenheit and Celsius, from 0 to 200. That works fine. Now, without guidance, I am writing the code for the so complex equation of y = mx + b. Whenever I run this, it only shows the output for 51 as x to 105 y! Here's the script:

    #import <Foundation/Foundation.h>
    int main (int argc, const char * argv[]) {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
            int xscope, yscope;
    	int slope = 2;
    	int intercept = 3;
    	for (xscope = 0; xscope <= 50; xscope = xscope + 1);
    		yscope = (slope * xscope) + intercept;
    		NSLog(@"%10.2i -> %10.2i", xscope, yscope);
        [pool drain];
        return 0;
    Thank you!
  2. chown33 macrumors 604

    Aug 9, 2009
    All your variables are of type int. Perhaps you want double or float.

    If you use double or float types, you must also change the format string of NSLog, otherwise the i conversion-specifier won't match the actual type, and you'll get garbage output. Refer to the String Format Specifiers document for the correct conversion.
  3. noahgolm thread starter macrumors member

    Aug 18, 2010
    Nope, still not working. Changed everything to the float, added the .0s just in case, and changed the is to fs. Still the same output.
  4. chown33 macrumors 604

    Aug 9, 2009
    Misplaced semicolon hilited above in red. This effectively defines an empty body for the 'for' loop. Remove semicolon to fix.

    Sorry for earlier misdirection. My net connection is flaky.
  5. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
    Remove the ; after the for ). That's gotten us all. The code in the block only runs once, with your variables in the state after the loop. Your loop body is an empty statement, so nothing happens each iteration.

    Int is fine here.


    Balls, slow phone typing.
  6. noahgolm thread starter macrumors member

    Aug 18, 2010
    Wow! Thanks! Now that I look at my previous temp converter code, that makes sense. Just gonna get comfortable with this kind of stuff before moving on to any kind of GUI whatsoever.

Share This Page