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 510571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:07:38+00:00 2026-05-13T07:07:38+00:00

I have a calculation which isn’t working and I cannot work out why! int

  • 0

I have a calculation which isn’t working and I cannot work out why!

int numHoursInWeek;
int numDays;
int averageSalary;

int total_seconds_in_year = ((numHoursInWeek * 60 * 60) * numDays);

NSLog(@"average sal in pence=%i", (averageSalary * 100));
NSLog(@"num seconds in year=%i", total_seconds_in_year);
NSLog(@"cost per second=%i", ((averageSalary * 100) / total_seconds_in_year));

int cost_per_person_per_second = ((averageSalary*100) / total_seconds_in_year);

costPerSecond = (cost_per_person_per_second * numPeople);
lblCostPerPerson.text = [NSString stringWithFormat:@"%.2f",cost_per_person_per_second];

the above returns the following in NSLog

average sal in pence=3400000
num seconds in year=31968000
cost per second=-1.991753

I know everything else is being set correctly (numDays, averageSalary for example).
When I do the calc manually, I get 0.1063. So that should show on my label?? (cost per person per second).

any ideas? should I be using floats instead of ints for the variables?

  • 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-13T07:07:39+00:00Added an answer on May 13, 2026 at 7:07 am

    When you do integer division, numbers are truncated, so:

    6 / 4
    >>> 1
    

    Change your data type to float or double, and write all of your numbers as “100.0” for example – otherwise it will be treated as an int.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 499k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The main win in AST interpretation vs. bytecode is operation… May 16, 2026 at 12:34 pm
  • Editorial Team
    Editorial Team added an answer If the source arrays don't have nil in them, you… May 16, 2026 at 12:34 pm
  • Editorial Team
    Editorial Team added an answer No, when you clone a Git repo, you get everything… May 16, 2026 at 12:34 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have here a button which calls a very long lasting calculation. To indicate
I have a C# method and which accepts three string parameters . After converting
I have designed a class which is basically nothing but an object which stores
Is it possible to sort on a calculation of 2 rows in mySQL? For
I have a Python program that runs a series of experiments, with no data
I have an jQuery accordion for a form on an internal company website. They
I have this function (produces the fibonacci sequence): unfoldr (\(p1, p2) -> Just (p1+p2,
I have an edge case. I'm building code that reads binary datafiles produced by
Suppose I have a SQL table of Awards, with fields for Date and Amount.
I'm trying to run the following program, which calculates roots of polynomials of degree

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.