Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7191143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:40:00+00:00 2026-05-28T19:40:00+00:00

I am new to Objective-C, so excuse me if this inherently doesn’t work in

  • 0

I am new to Objective-C, so excuse me if this inherently doesn’t work in the language, but it seems like it should. What I want to do is calculate the thickness of a book object in inches. Here are the objects in the Book header file:

NSString *title, *author;
int *numPages;
/**
 * The thickness of any given page in the book, in inches (e.g. 20lb stock would be 0.0038)
 */
double *pageThickness;
bool *hasHardCover;

The idea is that I’ll calculate the thickness of the book by adding (the product of the page thickness and the number of pages) with (the thickness of the book cover; a quarter inch if it’s hard cover, of four times the page thickness if it’s paperback). However, I get several errors with the following implementation:

63 -(int *)calculateWidthInInches
64 {
65  return (((double *)numPages) *
66          pageThickness) +
67  (hasHardCover ? 0.25 :
68   (pageThickness * 4.0));
69 }

Here are the errors:

/Users/student4/Downloads/LibraryOfBooks/Book.m:66: error: invalid operands to binary * (have 'double *' and 'double *')
/Users/student4/Downloads/LibraryOfBooks/Book.m:68: error: invalid operands to binary * (have 'double *' and 'double')
/Users/student4/Downloads/LibraryOfBooks/Book.m:69: warning: control reaches end of non-void function

I suspect that the last one was caused by failure to compile the return line. What have I done wrong with my calculateWidthInInches method?

Fix:


63 -(double)calculateWidthInInches
64 {
65  return ((*numPages) * *pageThickness) + (*hasHardCover ? 0.25 : (*pageThickness * 4.0));
66 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:40:01+00:00Added an answer on May 28, 2026 at 7:40 pm

    All your variables are pointers, not values. The compiler is complaining that you’re attempting to multiply pointers, an operation that doesn’t make sense.

    You need to dereference the pointers before multiplying in order to multiply the values, not the addresses of the values.

    EDIT: Also, as Yuras points out, casting the pointers directly is not a great idea — dereference the pointer, then cast the value:

    -(double)calculateWidthInInches
    {
        return (((double)*numPages) *
                pageThickness) +
        (*hasHardCover ? 0.25 :
         (*pageThickness * 4.0)); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

pretty new to objective-c, but i've encountered what seems to be a pretty common
Fairly new to Objective C and trying to work within Storyboards given it's the
New to objective-c and I just can't find the answer to this question anywhere.
New to Objective-C iPhone/iPod touch/iPad development, but I'm starting to discover lots of power
(New to Objective-C, but well versed in C/C++). Presently I have an Objective-C class
I am new to Objective-C and I want to let a screenshot made with
I am still new to objective-c and am trying to figure out what this
I am a new in objective-c, I want to know when I return an
I am a new to Objective-c, I want to get the detail infomation for
First of all, I am a a very new Objective C/Cocoa iOS Developer but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.