C# C# Help: Calculating Velocity Incrementally

  • Thread starter Thread starter Jarvis Bull Dawg
  • Start date Start date
AI Thread Summary
The discussion centers on creating a loop for a velocity calculation program that displays incremental results based on user input for time. The user wants to show velocities at increments of 5 seconds leading up to the total time entered (e.g., 25 seconds). Initial attempts at coding resulted in issues, including infinite loops and program freezes. Suggestions include using a for loop to iterate through time increments, calculating velocity using the formula v = a * t, and printing the results. A proposed solution involves initializing a variable for acceleration and using a for loop to increment time by 5 seconds, ensuring that the loop correctly displays the calculated velocities without causing errors. The conversation highlights the importance of proper loop conditions and variable management in programming.
Jarvis Bull Dawg
Messages
17
Reaction score
0
Hello everyone!

I have a question about a loop... Say I am making a velocity calculation, the user enters the time, the calculation happens... BUT I want the program to display the velocities in small increments leading to the final velocity. Say 25 seconds, I wan to to display it increments of 5, 10, 15, 20, & then 25. say in a lablel Now I can get a loop that will go upto 25 but I want it to display each of its results for say

a*t;
t= t+5;
...

Thank you !
 
Technology news on Phys.org
umm...if your input is 25 and you're setting it equal to t you'll have some problems...but I'm not sure if this is the problem you have...
 
t = 0;
while (t>25);
{ v= a * t;
t = t+ 5;
}
 
Last edited:
would it work better if you did something like this?:

int t;
int v;

t = console.readline();
for(i = 0; i i> t; i++)
{
v = a*t;
print(v);
t = t+5;
}

some of the commands aren't really what c# uses, but hopefully you'll get hte idea. the user inputs some time t, you execute a for loop, from 0 to t. you calculate the velocity at t, print the velocity, and then increase t by 5.
 
Nope that makes an infinite loop. The program freezes.
 
oh. do i < t then
 
I think we have to use some sort of a method to store the number and the recall it. I have no clue how to do this. Please anyone if they have an idea please do say so :(
 
Not sure i understand the issue, you mean something like the following?
Code:
int a = someNumber;
for (int t = 0; t <= 25; t += 5)
{
    Console.WriteLine("t=" + t + ", a=" + (a*t));
}
 

Similar threads

Back
Top