PDA

View Full Version : Why my program not work




A m a n y ~
Sep 1, 2009, 02:17 PM
hi every one here
how r u all ? :D
I hope all one here is fine

I try to learn these code ,, it's not from my mind ,, I'm just try to learn it then I will write nearly and same like it ,, but Xcode give me to problems
unfortunately I did not know it where in these code and how I fix it

#import <Foundation/Foundation.h>
typedef enum {
kCircle,
kRectangle,
kOblateSpheroid
} ShapeType;

typedef enum {
kRedColor,
kGreenColor,
kBlueColor
} ShapeColor;

typedef struct {
int x, y, width, height;
} ShapeRect;

typedef struct {
ShapeType type;
ShapeColor fillColor;
ShapeRect bounds;
} Shape;

int main (int argc, const char * argv[])
{
Shape shapes[3];
ShapeRect rect0 = { 0, 0, 10, 30 };
shapes[0].type = kCircle;
shapes[0].fillColor = kRedColor;
shapes[0].bounds = rect0;
ShapeRect rect1 = { 30, 40, 50, 60 };
shapes[1].type = kRectangle;
shapes[1].fillColor = kGreenColor;
shapes[1].bounds = rect1;
ShapeRect rect2 = { 15, 18, 37, 29 };
shapes[2].type = kOblateSpheroid;
shapes[2].fillColor = kBlueColor;
shapes[2].bounds = rect2;
drawShapes (shapes, 3);
return (0);
} // main


http://up.arab-x.com/Aug09/Dwo28968.jpg


thanx at all my lovers and dears
:rolleyes:



kainjow
Sep 1, 2009, 02:54 PM
Looks like you're calling drawShapes() which doesn't exist anywhere, or if it is you aren't compiling it with the rest of your code.

A m a n y ~
Sep 1, 2009, 10:12 PM
sorry
I am not understood

kainjow
Sep 2, 2009, 12:33 AM
You're calling a function named drawShapes. If you don't know why that is failing, I suggest you go pick up a book or tutorial on the C language.

A m a n y ~
Sep 2, 2009, 09:33 PM
thanx dear
I was learn some of c on windows ,, I was use C borland and netbeans
I know what does mean function ,,,
now I remember that ,,
:)


can I ask you small question
in c we was write {printf} for output
in objective C we write {NSLog} to include most thing

we was write {scanf} to give the input
what we can write in objective c ?

I'm sorry if my questions bother you ,,,

Sijmen
Sep 3, 2009, 12:53 AM
in c we was write {printf} for output
in objective C we write {NSLog} to include most thing

we was write {scanf} to give the input
what we can write in objective c ?

NSLog actually has quite a different use than printf. NSLog actually logs a line of text to the system logs, while printf just writes it to the console. That's why there's no such equivalent of scanf as you can't ask the log to type a line of text. I suggest just sticking with printf and scanf if that's what your book is working with. You can use them if you include their regular header.

A m a n y ~
Sep 14, 2009, 02:58 PM
#import <Foundation/Foundation.h>
typedef enum {
kCircle,
kRectangle,
kOblateSpheroid
} ShapeType;

typedef enum {
kRedColor,
kGreenColor,
kBlueColor
} ShapeColor;

typedef struct {
int x, y, width, height;
} ShapeRect;

typedef struct {
ShapeType type;
ShapeColor fillColor;
ShapeRect bounds;
} Shape;

int main (int argc, const char * argv[])
{
Shape shapes[3];
ShapeRect rect0 = { 0, 0, 10, 30 };
shapes[0].type = kCircle;
shapes[0].fillColor = kRedColor;
shapes[0].bounds = rect0;
ShapeRect rect1 = { 30, 40, 50, 60 };
shapes[1].type = kRectangle;
shapes[1].fillColor = kGreenColor;
shapes[1].bounds = rect1;
ShapeRect rect2 = { 15, 18, 37, 29 };
shapes[2].type = kOblateSpheroid;
shapes[2].fillColor = kBlueColor;
shapes[2].bounds = rect2;

drawShapes (shapes, 3);
return (0);
} // main


int drawShapes (Shape shapes[], int count)
{
int i;
for (i = 0; i < count; i++) {
switch (shapes[i].type) {

case kCircle:
drawCircle (shapes[i].bounds,
shapes[i].fillColor);
break;
case kRectangle:
drawRectangle (shapes[i].bounds,
shapes[i].fillColor);
break;
case kOblateSpheroid:
drawEgg (shapes[i].bounds,
shapes[i].fillColor);
break;

return(0);
}
}
}
int drawCircle (ShapeRect bounds,ShapeColor fillColor)
{


NSLog (@"drawing a circle at (%d %d %d %d) in %@",
bounds.x, bounds.y,
bounds.width, bounds.height,colorname(fillColor));
return(0);
} // drawCircle

NSString *colorname (ShapeColor colorname)
{
switch (colorname)
{
case kRedColor:
return @"red";
break;
case kGreenColor:
return @"green";
break;
case kBlueColor:
return @"blue";
break;
}
return @"dd";
} // colorName
#import <Foundation/Foundation.h>
typedef enum {
kCircle,
kRectangle,
kOblateSpheroid
} ShapeType;

typedef enum {
kRedColor,
kGreenColor,
kBlueColor
} ShapeColor;

typedef struct {
int x, y, width, height;
} ShapeRect;

typedef struct {
ShapeType type;
ShapeColor fillColor;
ShapeRect bounds;
} Shape;

int main (int argc, const char * argv[])
{
Shape shapes[3];
ShapeRect rect0 = { 0, 0, 10, 30 };
shapes[0].type = kCircle;
shapes[0].fillColor = kRedColor;
shapes[0].bounds = rect0;
ShapeRect rect1 = { 30, 40, 50, 60 };
shapes[1].type = kRectangle;
shapes[1].fillColor = kGreenColor;
shapes[1].bounds = rect1;
ShapeRect rect2 = { 15, 18, 37, 29 };
shapes[2].type = kOblateSpheroid;
shapes[2].fillColor = kBlueColor;
shapes[2].bounds = rect2;

drawShapes (shapes, 3);
return (0);
} // main


int drawShapes (Shape shapes[], int count)
{
int i;
for (i = 0; i < count; i++) {
switch (shapes[i].type) {

case kCircle:
drawCircle (shapes[i].bounds,
shapes[i].fillColor);
break;
case kRectangle:
drawRectangle (shapes[i].bounds,
shapes[i].fillColor);
break;
case kOblateSpheroid:
drawEgg (shapes[i].bounds,
shapes[i].fillColor);
break;

return(0);
}
}
}
int drawCircle (ShapeRect bounds,ShapeColor fillColor)
{


NSLog (@"drawing a circle at (%d %d %d %d) in %@",
bounds.x, bounds.y,
bounds.width, bounds.height,colorname(fillColor));
return(0);
} // drawCircle

NSString *colorname (ShapeColor colorname)
{
switch (colorname)
{
case kRedColor:
return @"red";
break;
case kGreenColor:
return @"green";
break;
case kBlueColor:
return @"blue";
break;
}
return @"dd";
} // colorName


it's all program ,,
also it's doesn't work
:(

A m a n y ~
Sep 16, 2009, 10:57 PM
:(

zippyfly
Sep 16, 2009, 11:08 PM
You seem to have pasted the code two times into the message.

Also the code is badly formatted.

I think it's quite hard for anyone to 1) see if the code is different or if you pasted it twice exactly and 2) see where the code blocks are because your indentation is so hard to read.

A m a n y ~
Sep 16, 2009, 11:48 PM
I will explain what these code do , and the function code
I tried to edit it , but I can not

I will try again :apple: