Amazon.com Widgets What makes a valid program statement? Exercise 6.6
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 24, 2013, 03:19:36 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
|-+  Programming in Objective-C, 4th edition
| |-+  Exercises
| | |-+  Chapter 6
| | | |-+  What makes a valid program statement? Exercise 6.6
Pages: [1]   Go Down
Print
Author Topic: What makes a valid program statement? Exercise 6.6  (Read 205 times)
stuartjj
Newbie
*
Posts: 11






« on: June 06, 2012, 07:11:11 AM »

I'm plugging away at exercise 6.6 and can't figure out what's wrong with the program statement (see below in context):
Code: (Objective-C)
for (resultedDivisor; resultedDivisor>=1; resultedDivisor/=10)
            resultedDigit=userEnteredNumber%resultedDivisor;       
I get the xCode error message: Expression result unused.  This error message refers to the variable "resultedDivisor".

Anybody know why I get this error message?  I guess in general I don't understand what makes a valid program statement. 
Code: (Objective-C)
int userEnteredNumber, divisor, resultedDivisor, resultedDigit;
       
NSLog (@"Enter your number.");
scanf ("%i", &userEnteredNumber);
       
       
        for (divisor=1; userEnteredNumber >= divisor; divisor*=10)
            resultedDivisor=divisor;   //produces 10^x where x = number of digits in userEnteredNumber
       
        NSLog(@"Resulted divsor = %i", resultedDivisor);
       
        for (resultedDivisor; resultedDivisor>=1; resultedDivisor/=10)
            resultedDigit=userEnteredNumber%resultedDivisor;               
       
       
    }
    return 0;
}
Logged
stuartjj
Newbie
*
Posts: 11






« Reply #1 on: June 06, 2012, 07:28:34 AM »

I solved part of this problem.  The issue was with the initial expression of the for statement, which read:
Code: (Objective-C)
for (resultedDivisor; resultedDivisor>=1; resultedDivisor/=10)  
            resultedDigit=userEnteredNumber%resultedDivisor;         
You have to have an assignment here, rather than just a variable.
Logged
john67
Newbie
*
Posts: 32






« Reply #2 on: June 17, 2012, 03:21:22 PM »

yeah, you've got it, more specifically its with this bit code....

Code: (Objective-C)
resultedDivisor/=10;

which is shorthand for

Code: (Objective-C)
resultedDivisor = resultedDivisor / 10;

this is an assignment

I think you should but the second code snippet actually in the loop

Code: (Objective-C)
for (resultedDivisor; resultedDivisor>=1;)
{
            resultedDivisor/=10;
            resultedDigit=userEnteredNumber%resultedDivisor;
}
« Last Edit: June 17, 2012, 03:22:59 PM by john67 » Logged
Pages: [1]   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.