Link to home
Start Free TrialLog in
Avatar of kensy11
kensy11Flag for Belgium

asked on

fi statement

hello,

I want to make these conditions :

If a user is member less then 5 years then the price is 135

if a user is member less then 10 years then he gets 10% discount
if a user is member less then 15 years then he gets 15% discount
if a user is member more then 15 years then he gets 30% discount

I like to code this but i'm stock

 public uint Lidgeld(uint year) {
            uint money = 135;
            uint temp = 0;
            if ((DateTime.Now.Year - year ) > 4 ){

                money = 135;
            }


            if ((DateTime.Now.Year - money) >= 9)
            {
                temp = money / 100 * 10;
                money = temp - money; 
            }
            return money;
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you can also use a select case / switch case depending on the code language
Avatar of kensy11

ASKER

I'm using c# but i thought it would be the same in different languages
If you're happy with a solution that is provided in another language then that's perfectly fine :)

Good luck.
Avatar of kensy11

ASKER

Thanks, ZOPPO

i have done what you told me, but its still not working fine

        public uint Lidgeld(uint year) {
            uint money = 135;
            uint temp = 0;
            uint difference = Convert.ToUInt16(DateTime.Now.Year - year);
            if (difference > 15)
            {
                temp = (135 / 100) * 30;
                money = 135 - temp;

            }
            return money;
        }

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kensy11

ASKER

ooh and the year is 1985
What exactly is going wrong?

The way you calculate the result is a bit complicated, you can do it easier - and I guess you need to use greater or equal comparsion, i.e.:
money = 135;
if (difference >= 15)
{
 money = money * 70 / 100;
}
else if ( difference >= 10)
{
 money = money * 85 / 100;
}
...

Open in new window

ZOPPO
Hi,

This might help!

   public uint Lidgeld (int year) {
            uint money = 135;
            DateTime now = DateTime.Now;
            DateTime origin = new DateTime(year, 01, 01);
            int Difference = now.Year - origin.Year;

            money = ((difference >15)? 135-  (135 / 100) * 30: (difference >10)? 135-  (135 / 100) * 15: (difference >5)? 135-  (135 / 100) * 10:135)
            
            return money;
        }                    

Open in new window


PS: Watchout for typos.

Regards
Kannan
Avatar of kensy11

ASKER

thank you all, i get it now


one other question how can i make the price look like this  50.00
i want the to see two numbers after the point like this  90.25
For this IMO you should use floating point numbers instead of uint.

>> i want the to see two numbers after the point ...
This depends a little bit on how you display it. I guess easiest is to convert the number to a string with Format - take a look here about this: http://www.csharp-examples.net/string-format-double/

ZOPPO
Avatar of kensy11

ASKER

my program looks like this now , but i have one other problem as you can see in

ConsCode.cs i am using
Console.WriteLine(L1.voornaam + " " + L1.naam + " " + ":" + "\t{0:0.00}", L1.Lidgeld(L1.jaar));

Open in new window

5times is there any way so i can write less and get the same result ??

thanks again

Program.cs

using System;

namespace ConsAppl1TI29
{
    class Program
    {
        static void Main(string[] args)
        {
            ConsCode Cc = new ConsCode();
            Cc.ExecuteProgram();
            Console.ReadKey(true);
        }/*Main*/
    }/*Program*/
}/*ConsAppl1TI29*/

Open in new window


Lid.cs
using System;

namespace ConsAppl1TI29
{
    class Lid
    {
        private string Naam;
        private string Voornaam;
        private uint Jaar;

        public Lid(string Naam, string Voornaam, uint Jaar)
        {
            this.Naam = Naam;
            this.Voornaam = Voornaam;
            this.Jaar = Jaar;
        }
            
       public Lid (string Naam, string voornaam) : this(Naam, voornaam, Convert.ToUInt16( DateTime.Now.Year))
        {

        }

        public string naam
        {
            get { return Naam; }
            set { Naam = value; }
        }

        public string voornaam
        {
            get { return Voornaam; }
            set { Voornaam = value; }
        }

        public uint jaar
        {
            get {
                if (Jaar == 0 || Jaar < 1932)
                {
                    Jaar = Convert.ToUInt16(DateTime.Now.Year);
                }
                return Jaar; }
            set {Jaar = value; }
        }

        public decimal Lidgeld(uint year) {
            decimal money = 135;
           
            uint difference = Convert.ToUInt16(DateTime.Now.Year - year);
            if (difference >= 15)
            {
                money = money * 70 / 100;
            }
            else if (difference >= 10)
            {
                 money = money * 85 / 100;
            }
            else if (difference >= 5)
            {
                money = money * 90 / 100;
            }
            
            return money;
        }

    }/*Lid*/
}/*ConsAppl1TI29*/

Open in new window


ConsCode.cs

using System;

namespace ConsAppl1TI29
{
    class ConsCode
    {
        public void ExecuteProgram()
        {
            Console.Title = ("Lidgelden jaar 2012");
            Leden();

            
        }/*ExecuteProgram*/
        private void Leden()
        {
            Lid L1 = new Lid("Jansen", "Piet");
            Lid L2 = new Lid("Roels", "Lut", 2003);
            Lid L3 = new Lid("Adams", "Tom", 1998);
            Lid L4 = new Lid("Dhondt", "Leen", 1985);
            Lid L5 = new Lid("Baert", "Jan", 1920);

            Console.WriteLine(L1.voornaam + " " + L1.naam + " " + ":" + "\t{0:0.00}", L1.Lidgeld(L1.jaar));
            Console.WriteLine(L2.voornaam + " " + L2.naam + " " + ":" + "\t{0:0.00}", L2.Lidgeld(L2.jaar));
            Console.WriteLine(L3.voornaam + " " + L3.naam + " " + ":" + "\t{0:0.00}", L3.Lidgeld(L3.jaar));
            Console.WriteLine(L4.voornaam + " " + L4.naam + " " + ":" + "\t{0:0.00}", L4.Lidgeld(L4.jaar));
            Console.WriteLine(L5.voornaam + " " + L5.naam + " " + ":" + "\t{0:0.00}", L5.Lidgeld(L5.jaar));

        }
    }/*ConsCode*/
}/*ConsAppl1TI29*/

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial