PDA

View Full Version : Help with basic Obj-c code?




macsrockmysocks
Jul 25, 2006, 03:36 PM
I have received my new book on ObjC today and am doing an exercise. Here is the code that I am having errors from:
#import <stdio.h>

int main(int argc, char *argv[])
{
int sum;
// Compute Result
sum = 25 + 37 - 19
// Display Results
printf ("The answer is %i\n", sum);

return 0;

}

It says there is a problem with my printf line, but I don't see it. Do any of you?



exabytes18
Jul 25, 2006, 03:49 PM
I don't program in obj-c, and don't know if this is a typo, but try adding a semicolon to make "sum = 25 + 37 - 19;"

macsrockmysocks
Jul 25, 2006, 04:09 PM
I cannot believe I missed that. I am so stupid! Oh well, you learn from mistakes. Now, I am off to Chapter 3- Objects.

mduser63
Jul 25, 2006, 04:10 PM
I don't program in obj-c, and don't know if this is a typo, but try adding a semicolon to make "sum = 25 + 37 - 19;"


That is most likely the problem. One thing you should learn is that often when the compiler complains about a particular line, it is often the line above it that's the real problem.