C# Help: Calculating Velocity Incrementally

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

Discussion Overview

The discussion revolves around calculating velocity incrementally in C#. Participants are exploring how to implement a loop that displays velocity at specified time increments based on user input, focusing on programming logic and syntax issues.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant describes a need to display velocity at increments of time leading to a final value, specifically mentioning a user input of 25 seconds.
  • Another participant raises a concern about potential problems with setting the input directly to the variable t.
  • A code snippet is provided that attempts to use a while loop, but it is noted that the loop condition is incorrect.
  • Another participant suggests using a for loop to iterate from 0 to the user-defined time, but acknowledges that some commands may not align with C# syntax.
  • One participant points out that the proposed for loop could result in an infinite loop, causing the program to freeze.
  • There is a suggestion to use a method to store and recall the calculated values, indicating uncertainty about how to implement this.
  • A later reply proposes a clearer for loop structure that correctly calculates and displays velocity at each increment, but it is unclear if this resolves the initial concerns.

Areas of Agreement / Disagreement

Participants express differing views on the correct implementation of the loop and syntax, with no consensus reached on a definitive solution. Some suggestions lead to confusion or errors, indicating ongoing uncertainty in the approach.

Contextual Notes

There are limitations in the provided code snippets, including incorrect loop conditions and potential infinite loops. The discussion also highlights a lack of clarity on how to store and recall calculated values effectively.

Who May Find This Useful

This discussion may be useful for individuals learning C# programming, particularly those interested in implementing loops and calculations based on user input.

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
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 14 ·
Replies
14
Views
35K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 60 ·
3
Replies
60
Views
9K