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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:31:15+00:00 2026-06-14T04:31:15+00:00

I have a for loop and inside that integer x will increase from 533

  • 0

I have a for loop and inside that integer x will increase from 533 to 813. That means 280 increments. In side the same loop I want to decrease y’s value from 300 to 200 when above happens. Which means when x is 533 y must be 300 and when x is 813 y must be 200. I know this can do by decrease y’s value by 100/280 in each iteration. But both are integers.

Here are some code sample i used but it is not working.:

for(int i = 0; i < b.getSize(); i++) {
            x = b.getCar(i).getPosX();
            b.getCar(i).setPosX(++x);
            if(x >= ((getWidth() / 2) - 140) && x < ((getWidth() / 2) + 140)){
                y = b.getCar(i).getPosY();
                y = (double)(y - (10.0f / 28.0f));
                b.getCar(i).setPosY((int)y);                    
            }
        }

How can I possibly do this. Thanks!

  • 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-06-14T04:31:16+00:00Added an answer on June 14, 2026 at 4:31 am

    There are two solutions, a simple and a complex one. The simple one:

    y = yoff + (int)( (double) height * x / width )
    

    where yoff = 300, height = -100, width = 813-533. Basically, you do a floating point operation and then you round the result.

    Alternatively, the same can be done using pure integer math using the Bresenham line algorithm but that would take a lot more code.

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

Sidebar

Related Questions

I have a for loop. Inside that loop I want to fill up an
Sometimes I have to check for some condition that doesn't change inside a loop,
I have a loop that could contain 1-10 records.... Inside that loop I am
So I have an array from 0-4, that has 5 random integer values (ie
I have below code. I wrote a for loop and inside that I have
I have the following loop inside an function init(); which is executed onload, I
I have some problems with controlling a while loop inside an event structure. Say
Hi I have a quick question, which is the easiest way to loop inside
I have this block of code inside a loop: var points = [new google.maps.LatLng(lat1,
I have the following code inside a loop: Range(N & i + 1).Formula =

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.