3 Replies - 489 Views - Last Post: 30 April 2014 - 05:02 AM Rate Topic: -----

#1 XanMan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-April 14

My answer is "0" way does he give me that?

Posted 28 April 2014 - 01:45 AM

namespace Pay
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        int days = 365;
        int months = 12;
        int eleven = Convert.ToInt32(0.11);
        int six = Convert.ToInt32(0.0065);


        private void button1_Click(object sender, EventArgs e)
        {
            int total;
            int pay;
            int aDays;

            pay = Convert.ToInt32(txtPay.Text);
            aDays = Convert.ToInt32(txtDays.Text);


           total = (pay * days / months) * (aDays * Convert.ToInt32(eleven * six));
           txtTotal.Text = (Convert.ToInt32(total).ToString());
         //  txtTotal.Text = total;

        }
    }
}


This post has been edited by Skydiver: 28 April 2014 - 05:40 AM
Reason for edit:: Put code in code tags. Learn to do this yourself.


Is This A Good Question/Topic? 0
  • +

Replies To: My answer is "0" way does he give me that?

#2 MrShoes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 312
  • View blog
  • Posts: 488
  • Joined: 13-June 12

Re: My answer is "0" way does he give me that?

Posted 28 April 2014 - 03:41 AM

If you convert 0.11 and 0.0065 to an int, what are you expecting the result to be?
Was This Post Helpful? 0
  • +
  • -

#3 Robbss  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 56
  • Joined: 26-December 10

Re: My answer is "0" way does he give me that?

Posted 28 April 2014 - 03:47 AM

If you post again, please explain your problem more precisely, tell us what you're doing, you could've mentioned that you have 3 text boxes and a button on your form.
However your problem is that you're converting your numbers to integers, integers can only hold whole numbers, so 0.11 cannot fit in an integer, therefore it is rounded and then becomes 0, the same with your 0.0065 value.

So what you're doing is (pay * days / months) * (aDays* 0) or, (pay * days / months) * 0, that's why it'll always be zero.

You can read up about the different data types that are in C# and find the one that fits your need, Integer is not the one.
Was This Post Helpful? 2
  • +
  • -

#4 XanMan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-April 14

Re: My answer is "0" way does he give me that?

Posted 30 April 2014 - 05:02 AM

Thank you for this. Sorry I'm a student and still new in this world. :smile2:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1