[C#] Please why is the area of the triangle in this my code 0 it should be 15

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace variable
{
    class Program
    {
        static void Main(string[] args)
        {
            // int a =3 + 6;
            // int b = 5 -7;
            // int a;
            // a =3 + 6;
            // b =5 + 7;
            // int a = 6
            // b =c +5;
            // v = b -j ;
            // double moneymadefromgames = 100000;
            // double totalprogrammers = 4;
            // double moneyperperson = moneymadefromgames / totalprogrammers; 
            // the formular for area of circle is pi * r ^ 2;
            // the formular for area of triagle is 1/2 b * h;
            float b = 5;
            float height = 6;
            double area = 1/2 *b *  height;
            Console.WriteLine("the areas of triagle is " + area);
            int score;
            int age;
            age = -89;
            score = 33;
            int loan;
            int credit;
            float radius = 4;
            float pi = 3.1415926536f; // the 'f' makes it a float literal instead of a double literal.
            float newarea = pi * radius * radius;
            // using the + operator with strings results in "contatenation".
            Console.WriteLine("The area of the circle is " + newarea + ".");
           
          

            loan = 2000;
            credit = 5000;
            float totalcost = 22.54F;
            float tipPercent = 0.18F;
            float tipAmount =  totalcost * tipPercent;
            double moneymadefromgames = 100000;
            double totalprogrammers = 4;
            double moneyperperson = moneymadefromgames / totalprogrammers;
            System.Console.WriteLine(moneyperperson);
            System.Console.WriteLine(score - age);
            System.Console.WriteLine("PRESS ANY key to exit");
            System.Console.WriteLine(loan + credit);
            System.Console.WriteLine(tipAmount);
            System.Console.Read();
            
        }
    }
}

what language are you using?
what should your code be doing?
what is it doing instead?
what have you tried to debug?


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

| ieahleen Leader
October 8 |

  • | - |

what language are you using? c#
what should your code be doing? the code that talks about area of triagle shall display 15 not 0
what is it doing instead? the line below:

float b = 5;
float height = 6;
double area = 1/2 *b * height;
Console.WriteLine("the areas of triangle is " + area);

what have you tried to debug? the area of the triagle.

Thank you ieahleen

what have you tried to do to debug it

I have no knowledge of C#, but if you use 0.5 instead of 1/2 it works

Dear Inelia,
You are very smart.
Meanwhile can you please tell me the languages you had mastered ?
Thank you .
Gbenga

I have not mastered any language

The language I am most confortable with is JavaScript, and am starting to familiarize with Python

thanks for this.I will be in touch as after this my c# foundation it will be javascript.
thanks once again Inelia.

whenever you have a question, you can create a topic in the freeCodeCamp forum, there is always someone around willing to answer questions

Because 1 and 2 are integers, C# is going to perform integer division. This means that 1/2 * b * height is 0 * 5 * 6.

Dear Inelia,
You mentioned my codes were not proper ly arranged.
Please can you tell me what I shall always do the next time?
Thanks so much.
Gbenga

use backticks, as I wrote in that other post

also, if you really want to use my given name instead of my username, please spell it correctly…

1 Like

Please kindly tell me how to use/type your name?
Thanks.
Gbenga

image

1 Like

If you use an “@” and then start typing a username, the forum will start suggesting usernames, so you don’t have to worry about misspelling ;).

1 Like

@ieahleen.I tried this and it works fine my good couch.
Cheers.

@ArielLeslie .Good morning.Thanks always.How do you read your programming books?Soft copies on electronic devices or the printed copies? I am having it hard reading the soft copies.Hard copies read faster by me.
Please share your experience.
Thanks

I rarely read programming books at all.

1 Like

That is great.So how do you learn?
Thanks.
Gbenga