vconfusedrn
vconfusedrn

Reputation: 33

Getting an error in Console.WriteLine code for c# in VS

I am just starting c# and I am currently working on a project where I need to check what discount someone gets based on how much they bought. Everything is working until I get to the Concole.WriteLine part.

public decimal GetDiscount(decimal unitPrice, int unitAmount)
    {
        if (unitAmount < 99 && unitAmount >= 50){
            decimal discount = .10m;
            return (unitAmount * unitPrice) * discount; 
        }
        if (unitAmount >= 99 ){
            decimal discount = .15m;
            return (unitAmount * unitPrice) * discount; 
        }
        return 0;
    }
    Console.WriteLine(GetDiscount(8, 78));
    Console.WriteLine(GetDiscount(3, 42));
    Console.WriteLine(GetDiscount(17, 150));
    Console.WriteLine(GetDiscount(5, 3));

At that point right at the fist parentheses of Console.WriteLine I get the error of "invalid token" Then next is the last parentheses where it says "Tuple must have two elements" and that the number I put for the first value is invalid. This is my first c# project so I am just lost now with what is wrong

Upvotes: 0

Views: 111

Answers (1)

Zoyeb Shaikh
Zoyeb Shaikh

Reputation: 334

    public class Program
    {
        public static decimal GetDiscount(decimal unitPrice, int unitAmount)
        {
            if (unitAmount < 99 && unitAmount >= 50)
            {
                decimal discount = .10m;
                return (unitAmount * unitPrice) * discount;
            }
            if (unitAmount >= 99)
            {
                decimal discount = .15m;
                return (unitAmount * unitPrice) * discount;
            }
            return 0;
        }
        public static void Main()
        {    
            Console.WriteLine(GetDiscount(8, 78));
            Console.WriteLine(GetDiscount(3, 42));
            Console.WriteLine(GetDiscount(17, 150));
            Console.WriteLine(GetDiscount(5, 3));
        }
    }
  • outupt :- every thing is just working fine
  • 62.40
  • 0
  • 382.50
  • 0

Upvotes: 2

Related Questions