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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:58:29+00:00 2026-05-22T15:58:29+00:00

Here is a program that models a tennis ball being thrown off the side

  • 0

Here is a program that models a tennis ball being thrown off the side of a 50 meter building.
The program should output the x, y, and velocity values at each time step.
However, I seem to be getting an infinite loop.

 #include<stdio.h>
 #include<math.h>

 int main() {

     //Intial values 
     float ax = 0; //acceleration in the horizontal direction
     float ay = -9.8; //acceleration in the downward direction
     float x = 0; //top of building at position 0 
     float y = 50; //building is height 50 m
     float vx = 10*cos(30); //velocity in the horizontal direction = 10 m/s * cos(30); 
     float vy = 10*sin(30); //velocity in the vertical direction = 10 m/s * sin(30);     
     int time = 0; //time starts at 0 seconds
     float deltaTime = 0.001; //increment time by .001 each iteration

     //while ball is greater than 0, or above the ground which is at position 0
     while(y > 0) {

     time = time + deltaTime;
     vx = vx + ax*deltaTime;
     vy = vy + ay*deltaTime;
     x = x + vx*deltaTime + (1/2*ax*deltaTime*deltaTime);
     y = y + vy*deltaTime + (1/2*ay*deltaTime*deltaTime);     

     printf("x = %f, y = %f, vx = %f, vy = %f, time = %d, ", x,y,vx,vy,time);

     }
     system ("PAUSE"); 
     return 0;

 }

My guess is that y will never become smaller than 0, but because of my limited physics knowledge, I don’t know how I could fix it.

  • 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-22T15:58:30+00:00Added an answer on May 22, 2026 at 3:58 pm

    1/2 == 0 not 0.5

    Since 1 and 2 are both integers this uses integer division which truncates to the closest integral number. Use 0.5f to get a float or just 0.5 to get a double.

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

Sidebar

Related Questions

first question here. I'm developing a program in C# (.NET 3.5) that displays files
I have a C# program that uses a production grammar to generate 3D models
I have a program here that has an entry box and a button. I
Hi here is my problem. I have a program that calulcates the averages of
This is beyond both making sense and my control. That being said here is
Just wondering what little scripts/programs people here have written that helps one with his
I have a program here: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/ipc.h> #include
I've got a Schroedinger's Cat type of problem here -- my program (actually the
Okay here's the program I have typed up(stdio.h is included also): /* function main
Here is a quick test program: public static void main( String[] args ) {

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.