Amazon.com Widgets Recent Posts
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 20, 2014, 01:03:25 AM
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
|-+Recent Posts
Pages: 1 2 [3] 4 5 ... 10

 21 
 on: October 11, 2014, 09:44:40 AM 
Started by jonr - Last post by jonr
Brian,
Thanks for this info.  I think I got a little lazy checking to see if the cause was an Xcode version issue.  I have a 4th edition hard copy and a 6th edition eBook version and on my 6th edition copy of the book I can see by the printing date and looking at various Xcode release dates that an Xcode version < 5.1.1 had to be used for the book.  Sure enough when looking at the screen captures at the beginning of the book, I see that version 5.0 was used.  When reading up on some of the changes between Xcode 5.0 and 5.1 / 5.1.1, compiler changes were in the feature list.

Btw, I would think that having the compiler be able to flag this before you attempt a build would be considered an improvement.  Do you agree?  It just seems to me that it's more intelligent and proactive in finding code problems.

Thanks for explaining that compile/build is essentially the same thing.  I must need a new pair of glasses Smiley as I see that Build (Command-B) is listed right there in the Product menu and I do see Compile in Product -> Perform Action.  Thanks for taking the time for pointing this stuff out.

Btw, I do have Xcode 6 installed but I've been using 5.1.1 for the book thinking that it may be better to use a version closer to the book's version . I may install 5.0 just to get completely in sync with the book in case there are other issues such as this one.
Cheers,
jonR

 22 
 on: October 10, 2014, 09:19:03 PM 
Started by windallt23 - Last post by BrianLawson
how do i create list such, for the user to choose what type of math the user wants to use such as choose:
1. addition
2.subtraction
3. multiplication
4. division

Use a series of NSLog statements as a prompt or just prompt the mathematical operator wanted and accept a char from the user. Reading a single character has some problems to work around when an invalid operator is entered. Here is one way to do this program using the char input method:
Code: (Objective-C)
#import <Foundation/Foundation.h>

// Generate random number between 1 and 20
int getRandomNumber() {
return (arc4random()%(20-1))+1;
}

int main(int argc, const char * argv[])
{
@autoreleasepool
{
// How many questions are to be asked
const int numQuestions = 5;

// For counting the number of correct answers
int correct = 0;

for (int i = 0; i < numQuestions; ++i) {
NSLog (@"Problem %i", i + 1);

float answer = 0.0;

// random number generator
int rnum1 = getRandomNumber();
int rnum2 = getRandomNumber();

// select math type
char operator;

// When scanf is used, the Enter character the user presses to enter the answer
// is also put into the buffer. The next read for a character will see that Enter
// character. throwAway is used to prevent operater from reading that Enter character.
char throwAway;

NSLog (@"please select math operation:");
scanf("%c", &operator);

BOOL validOperator = true;
// calculate answer to problem or display invalid operator error message
switch(operator)
{
case '+':
answer = rnum1 + rnum2;
break;
case '-':
answer = rnum1 - rnum2;
break;
case '*':
answer = rnum1 * rnum2;
break;
case '/':
answer = (float)rnum1 / (float)rnum2;
break;
default:
validOperator = false;
NSLog(@"ERROR: Invalid math operator %c", operator);
--i; // Don't count an invalid operator in the number of questions asked.
scanf("%c", &throwAway); // Clear the enter character from the input buffer.
break;
}

if (validOperator) {
NSLog(@"%i %c %i = ", rnum1, operator, rnum2);

// user enter answer to problem
float number;

scanf ("%f%c", &number, &throwAway);

if (number == answer ) {
++correct;
} else {
NSLog(@"The correct answer is %.1f", answer);
}
}
}

// Display results
// %% needed to print single % in results message
NSLog(@"Your score is %.1f%%, you missed %i questions.", ((float)correct / numQuestions * 100), (numQuestions - correct));
}

return 0;
}

 23 
 on: October 10, 2014, 06:56:21 PM 
Started by windallt23 - Last post by windallt23
how do i create list such, for the user to choose what type of math the user wants to use such as choose:
1. addition
2.subtraction
3. multiplication
4. division

then have the two random numbers do the type of math selected. this is what i have so far.
#import <Foundation/Foundation.h>
#import "myMath.h"

int main(int argc, const char * argv[])
{

    @autoreleasepool
    {
        // 5 loops before calculating percentage
        int count = 1;
        while (count <= 5){
            NSLog (@"%i", count);
            ++count;
           
        // select math type
            enum equation {1. = add, sub, mult, divi};
            enum equation entry;
            NSLog (@"please select equation");
            scanf("%i", &entry);
           
            switch(entry)
            {
                case 1:
                    NSLog(@"addition");
                case 2:
                    NSLog(@"subtraction");
                case 3:
                    NSLog(@"multiplication");
                case 4:
                    NSLog(@"division");
            }
       
        // random number generator
        myMath *myMathStuff;
        myMathStuff = [[myMath alloc] init];
       
        int rnum1 = [myMathStuff getRandomNumber];
        int rnum2 = [myMathStuff getRandomNumber];

       
        NSLog(@"The random numbers are %i and %i", rnum1, rnum2);
       
        // user enter answer to problem
        int number;
       
        NSLog (@"Type in your answer:");
        scanf ("%i", &number);
       
       
        }
    }
   
    return 0;
}

 24 
 on: October 10, 2014, 06:21:51 PM 
Started by jonr - Last post by BrianLawson
You are seeing a different error message because you are using a different version of Xcode than what was being used when the book was written. Depending upon exactly which version of Xcode the author was using you could even be using a completely different compiler. That could also explain why the program would run in the older version but not in the newer version.

To compile without running the program, use the Build command (Command-B). While technically different, in Xcode, a compile and build is essentially the same thing. Look under the Program menu's Perform Action command and there may be a Compile command for you. This will compile just the file you are currently displaying in the editor. I'm using Xcode 6 now so I can't check to see it that was available in Xcode 5.

 25 
 on: October 10, 2014, 05:39:48 PM 
Started by jonr - Last post by jonr
In chap. 9 there is a simple example in the section 'Compile Time Versus Runtime Checking' and shows what happens when you send an incorrect method to an instance.  The example uses a simple situation based on programs 9.1 and 9.2 where there are two classes, Fraction and Complex.  A fraction object is sent a message that is from the Complex class:
Code: (Objective-C)
[f1 setReal: 10 and Imaginary: 2.5];
  The books says that the following message is issued when you compile the program that contains this line:
Quote
"'Fraction' may not respond to 'setReal:andImaginary:'"
  This is easily understandable but I'm not seeing this exact result.  For me, in Xcode 5.1.1 flags this as an error and it won't even build.
Quote
The message states "No visible @interface for 'Fraction' declares the selector 'setReal:andImaginary:'"
  In other words I see this message displayed right in main.m. If I ignore the message and try to 'Run' I get a 'Build Failed' message.

Why am I seeing an outcome different from the book?  Is there a setting in Xcode that determines this?  One thing I can't figure out in Xcode is how to do a Compile without Running.  If it's possible in Xcode, I can't figure out where in the UI to do that.  I'm thinking that this could be the problem, but I'm not sure.  In fact, putting aside the issue of actually running the code, is there a way in Xcode to just do a Compile and not a full Build? I'm thinking that this could be the reason I'm seeing different results, but again I'm not sure. Any info would be most welcomed!
thanks,
jonR

 26 
 on: October 09, 2014, 08:18:22 PM 
Started by deathkamp - Last post by deathkamp
Hi i am just wondering how I would go about using objective c to analyze a photo by displaying text that is summarizing/describing key points, main idea ect, of that photo. Its an algorithm simliar to how googles search by image works but without the search, and more of the analyzing by shapes,color etc.? Would i need a data base of words too since the code will need something to display the summary?

 27 
 on: October 09, 2014, 02:02:29 PM 
Started by windallt23 - Last post by BrianLawson
For a program like this, you don't really need to have any classes. Convert the getRandomNumber method into a plain function that can be called from main. Create a for loop and inside it generate your two random numbers. Display a prompt for the type of operation the user wants to be tested on and get the response. Use the response to generate an equation that you display to the user as a prompt for the answer. Get the answer and test it to see if it is correct. If it is, increment the correct answer counter. You do not need to count the number of wrong answers as it can be calculated from the number of questions asked minus the number of correct answers. The percentage correct is (number correct) /  (number of questions asked) * 100.0. Be sure to initialize the correct answer counter to zero before you enter the loop and display the results when the loop has finished.

 28 
 on: October 09, 2014, 09:53:59 AM 
Started by windallt23 - Last post by windallt23
how to create an application that will help a student learn math. program should loop 5 times. Each time it runs through a loop, it should ask the student whether he wants to perform multiplication, division, addition or subtraction. For each, you will display the equation and ask the user for the result of the equation. Get the users input and then check to see if the result
is correct. If it is, congratulate the user and add 1 to the correct count. If it is not correct, show the user the correct answer and add 1 to the incorrect count. When the program finishes the 5 loops you should display the studentís number correct,
number incorrect and their score as a percentage. I donít want to see that they got 4 out of 5 correct. I want to see that they received an 80. here is what i have to start with.

main.m

#import <Foundation/Foundation.h>
#import "myMath.h"

int main(int argc, const char * argv[])
{

    @autoreleasepool {
        myMath *myMathStuff;
        myMathStuff = [[myMath alloc] init];
       
        int rnum1 = [myMathStuff getRandomNumber];
        int rnum2 = [myMathStuff getRandomNumber];

       
        NSLog(@"The random numbers are %i and %i", rnum1, rnum2);
       
       
    }
    return 0;
}




myMath.h

#import <Foundation/Foundation.h>

@interface myMath : NSObject


//declare methods

-(int) getRandomNumber;

@end




myMath.m

#import "myMath.h"

@implementation myMath


//returns a random number between 1 and 20
-(int) getRandomNumber{
    return (arc4random()%(20-1))+1;
}
@end




 29 
 on: October 08, 2014, 07:48:40 AM 
Started by allc1865 - Last post by allc1865
Hi, I'm trying to create an inApp text messenger where you can send and receive text messages.
Is there any way to do this?

Thanks! Smiley

 30 
 on: October 07, 2014, 08:09:25 AM 
Started by jnbutler1815 - Last post by jnbutler1815
Will there be a forum for Programming in C Fourth Edition?

Pages: 1 2 [3] 4 5 ... 10


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.