A little C# help.

  • #1
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 !
 

Answers and Replies

  • #2
46
0
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...
 
  • #3
t = 0;
while (t>25);
{ v= a * t;
t = t+ 5;
}
 
Last edited:
  • #4
46
0
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.
 
  • #5
Nope that makes an infinite loop. The program freezes.
 
  • #6
46
0
oh. do i < t then
 
  • #7
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 :(
 
  • #8
-Job-
Science Advisor
1,146
1
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));
}
 

Related Threads on A little C# help.

  • Last Post
Replies
2
Views
5K
  • Last Post
Replies
11
Views
2K
  • Last Post
Replies
10
Views
3K
Replies
1
Views
1K
  • Last Post
Replies
3
Views
1K
Replies
2
Views
1K
Replies
1
Views
924
Replies
6
Views
764
  • Last Post
Replies
6
Views
3K
  • Last Post
Replies
2
Views
1K
Top