83Views3Replies

Author Options:

Need help with Xcode Answered

Okay so I'm new to Xcode and programming so this question may seem very stupid.
Here's my code. Basically the problem is that I can't get decimal numbers to print out... I know it' s really stupid. If you go to the bottom you will see "x = x - 0.1;" and instead of printing out that number - 0.1 it prints it out the number  - 1. It's not even close to done but I would really appreciate some help!

Here's my code
int main(int argc, char * argv[])
{
    @autoreleasepool
    {
        int number;
        int x;


        NSLog(@"squareroot program!");
        scanf("%i" , &number);


        x = number/2;

        if(x * 2 == number)
        {
        NSLog(@"%i", x);

        }
        if( x != number)
        {
            x = x - 0.1;

        }
        NSLog(@"%i", x);
    }
    return 0;
}

Comments

The forums are retiring in 2021 and are now closed for new topics and comments.
0
Sorunome
Sorunome

Best Answer 7 years ago

I never did Xcode, but it looks like in your NSLog function you are telling it to print an integer ( %i ) which is only whole numbers. You'll want to display floats, i think it is %f .

0
Sorunome
Sorunome

Answer 7 years ago

also, you declare your number x as an integer, try 'float x;' instead.

0
Kenii
Kenii

Answer 7 years ago

OMGOMG WOAH WOAH *facepalm* THANKS FOR REMINDING ME ABOUT FLOATS!!!!!