-4

I am trying to multiply a decimal but I am getting an error.

The child ticket is 50% of the cost of the Adult ticket. And the Seniors ticket is 70% of the Adult ticket. Error is telling me that the * operator cannot be applied to doubles or multiples..

I tried to use brackets to isolate the caculation.. but I am still getting the operand error.

Console.Write("Enter the cost of one Adult ticket: $");
decimal CostAdult = Convert.ToDecimal(Console.ReadLine());

decimal revenue1 = CostAdult * Adult;
Console.WriteLine("You have made " + revenue1.ToString("C") + " for Adult ticket sales!");
Console.ReadLine();

decimal revenue2 = CostAdult * Child * 0.5;
Console.WriteLine("You have made " + revenue1.ToString("C") + " for Senior ticket sales!");
Console.ReadLine();

decimal revenue3 = CostAdult * Senior * 0.7;
Console.WriteLine("You have made " + revenue1.ToString("C") + " for Senior ticket sales!");
Console.ReadLine();
Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
  • 3
    _Error is telling me that the * operator cannot be applied to doubles or multiples.._ - you will always get better answers if you include **the actual error message** rather than your interpretation of it. – stuartd Apr 09 '23 at 00:28
  • According to [Floating-point numeric types (C# reference)](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types#real-literals): _The type of a real literal is determined by its suffix as follows: The literal without suffix or with the d or D suffix is of type double. The literal with the f or F suffix is of type float. The literal with the m or M suffix is of type decimal._ Also see [Built-in types (C# reference)](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/built-in-types) – Tu deschizi eu inchid Apr 09 '23 at 01:32

1 Answers1

-1

You have to add M after the value when assigning an decimal.

decimal revenue = 0.5M;

Paul Albers
  • 121
  • 1
  • 8
  • 4
    "after assigning" is incorrect terminology. You are adding an "m" _suffix_ to a literal to create a _decimal literal_. – gunr2171 Apr 09 '23 at 00:55
  • Sorry! I'm from the netherlands. Sometimes I mess things up... :) – Paul Albers Apr 09 '23 at 01:41
  • 1
    *"when assigning an [sic] decimal"* is still wrong. If you're assigning a decimal that's not a literal decimal expression, the suffix is irrelevant. The suffix specifically has to do with the literal value. Whether you're assigning to something or passing it as a parameter doesn't matter. – madreflection Apr 09 '23 at 02:18