Amazon.com Widgets Having trouble using NSLog with type double
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 01, 2014, 06:09:39 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
| |-+ Chapter 4
| | |-+ Having trouble using NSLog with type double
Pages: [1] Go Down
Print
Author Topic: Having trouble using NSLog with type double (Read 1268 times)
WorldBuilder
Newbie
*
Posts: 4






on: January 09, 2012, 04:44:05 PM

Here is my code:
@autoreleasepool {
        double imaginary1;
       
        NSLog(@"Enter your imaginary number.");
        scanf("%f", &imaginary1);
       
        NSLog(@"Your number is: %f", imaginary1);
        NSLog(@"Program End.");
    }
    return 0;
}

And here is my Output:
Enter your imaginary number.
3.0
Your number is: 0.00000
Program End.


So, what is the proper NSLog char for type double?
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







Reply #1 on: January 09, 2012, 06:00:24 PM

Use %lf for the scanf call, as that's more critical.   You can use that for the NSLog as well.   

Cheers,

Steve
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.