Amazon.com Widgets Exercise 8.8 using MIN and MAX Functions
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 18, 2013, 09:27:53 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Answers to Exercises
| | |-+  Chapter 8
| | | |-+  Exercise 8.8 using MIN and MAX Functions
Pages: 1 [2]   Go Down
Print
Author Topic: Exercise 8.8 using MIN and MAX Functions  (Read 3126 times)
chrisherbert
Newbie
*
Posts: 8






« Reply #15 on: September 16, 2009, 01:27:09 PM »

Remember, = is for assignment, == is the equality test operator.

Cheers,

Steve


Arggh. Not the first time I've been caught out by that! Thanks...
Logged
cduquette
Newbie
*
Posts: 1


Email




« Reply #16 on: June 15, 2010, 04:57:39 PM »

Yeah, mine was basically nested loops as well.  I do have a question, though.

Is there a way to repeat characters to create a string?

For example:

top = '-'*6;



You can't repeat characters in a string, but you can pad output with spaces.  This makes the draw logic a bit simpler:

-(void) draw
{
   int k;
   
   for (k = 0; k < width; k++) printf("_"); printf("\n");
   
   for (k = 0; k < height; k++) printf("|%*s\n",width-1,"|");   // '|' then '|' width-1 spaces away
   
   for (k = 0; k < width; k++) printf("_"); printf("\n");
}
Logged
marks
Newbie
*
Posts: 12






« Reply #17 on: October 10, 2010, 09:22:15 AM »

Hi, this is my attempt on the exercise 7.
Code: (Objective-C)
-(void) draw
{
NSLog (@"Width: %d , Height: %d", self.width, self.height);

// top
printf(" ");
for (int i = 0;i < self.width; i++) {
printf("_");
}

printf ("\n");

//middle
for (int i = 0; i < self.height; i++) {
printf("|");

for (int x = 2; x < self.width + 2; x++) {
printf(" ");
}

printf("|\n");
}

// bottom
printf(" ");
for (int i = 0;i < self.width; i++) {
printf("-");
}

}


This will draw 10 space block inside for the Rectangle, looks similar to this in xcode console.

2010-10-11 00:23:21.075 Exercise7[11429:a0f] Width: 10 , Height: 3
 __________
|                 |
|                 |
|                 |
 __________
« Last Edit: October 10, 2010, 09:25:11 AM by marks » Logged
Pages: 1 [2]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.