Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

A little C# help.

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

    -Job-

    User Avatar
    Science Advisor

    Not sure i understand the issue, you mean something like the following?
    Code (Text):

    int a = someNumber;
    for (int t = 0; t <= 25; t += 5)
    {
        Console.WriteLine("t=" + t + ", a=" + (a*t));
    }
     
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: A little C# help.
Loading...