Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9146099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:40:32+00:00 2026-06-17T10:40:32+00:00

In my program I’ve defined some variables in button1_Click and also there is a

  • 0

In my program I’ve defined some variables in “button1_Click” and also there is a “for” loop in “button1_Click” function. In that loop I want those variables to be changed, but they don’t.
What should I be doing…passing them by reference? If yes, how?

private void button1_Click(object sender, EventArgs e)
        {
            double t=0;
            double x = double.Parse(X0.Text);
            double z = double.Parse(Z0.Text);
            double y = double.Parse(Y0.Text);
            double u = double.Parse(U0.Text);
            double tn = double.Parse(Tn.Text);
            double h = double.Parse(textbox_h.Text);

            for (int i = 0; i < (tn / h); i++)
            {

                double K1x = h * fx(t, x, y, z, u);

                double K2x = h * fx(t + h / 2, x + K1x / 2, y + K1y / 2, z + K1z / 2, u + K1u / 2);

                double K3x = h * fx(t + h / 2, x + K2x / 2, y + K2y / 2, z + K2z / 2, u + K2u / 2);

                double K4x = h * fx(t + h, x + K3x, y + K3y, z + K3z, u + K3u);


                x =x+ (1 / 6)*(K1x + 2 * K2x + 2 * K3x + K4x);
                richTextBox1.Text += "X(" + (h * (i + 1)).ToString() + ")=" + x.ToString();


            }

All things are right but at the last line, new values of x doesn’t go in x, and the old ones remain.
Note that fx, fz,fy,fu are functions that I’ve defined before.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:40:33+00:00Added an answer on June 17, 2026 at 10:40 am

    The problem is that 1 / 6 is 0, because both 1 and 6 are int, so the result will also be an int. An int can’t have any decimals, so they are simply dropped, there is no rounding happening. And 0.16666666... without the decimals is 0.

    To fix it, make at least one of the two a double or float:

    1.0 / 6
    

    The complete line should now look like this:

    x = x + (1.0 / 6)*(K1x + 2 * K2x + 2 * K3x + K4x);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My program need to occupy some resources. I want it to release those resources
This program runs just fine, but for some reason when I ask for an
(C PROGRAM) I'm trying to compile a main.c that uses a header but I'm
My program exits when main function tries to run some class (Rock) more than
Program that tests the rand function is an example: <?php class number { function
Program that calculates and shows the value of (2 to the 10th power) This
My program runs fine in Netbeans, but I get the following error when I
My program gets stuck in the simple call usleep(1.); . How can that be?
My program draws text on its panel,but if I'd like to remove the text
Program A, is a c program that endlessly, receives input in stdin, process it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.