C# Help: Calculating Velocity Incrementally

  • Context: C# 
  • Thread starter Thread starter Jarvis Bull Dawg
  • Start date Start date
Click For Summary
SUMMARY

The discussion centers on calculating velocity incrementally in C# based on user input for time. The user seeks to display velocity results at intervals of 5 seconds leading up to a specified time, such as 25 seconds. A working solution is provided using a for loop that iterates from 0 to the user-defined time, calculating velocity with the formula v = a * t and printing the results. The final code snippet demonstrates the correct implementation of the loop to avoid infinite loops and ensure proper output.

PREREQUISITES
  • Understanding of C# programming language
  • Familiarity with loops and conditional statements in C#
  • Basic knowledge of velocity calculation formulas
  • Experience with console input and output in C#
NEXT STEPS
  • Explore C# for loops and their syntax in detail
  • Learn about user input handling in C# using Console.ReadLine()
  • Investigate methods for storing and recalling values in C#
  • Study debugging techniques to prevent infinite loops in C# applications
USEFUL FOR

C# developers, students learning programming concepts, and anyone interested in implementing incremental calculations in console applications.

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

  • · Replies 32 ·
2
Replies
32
Views
4K
Replies
1
Views
2K
  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 4 ·
Replies
4
Views
6K
Replies
10
Views
2K
Replies
4
Views
2K
  • · Replies 14 ·
Replies
14
Views
34K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 60 ·
3
Replies
60
Views
9K