FAQ: Working with Numbers - Numerical Data Types

This community-built FAQ covers the “Numerical Data Types” exercise from the lesson “Working with Numbers”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn C#

FAQs on the exercise Numerical Data Types

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Why do we use a decimal in the cause for revenue = 390819.28. Shouldn’t we use double for this since its not a financial application ?

this looks alot like python to me :confused: number wise

It is a financial application. Revenue refers to the total amount of money that the company has brought in. It’s actually $390 819.28

1 Like

Hello ! I have a code:

using System;

namespace Numbers
{
class Program
{
static void Main(string args)
{
int pizzaShops = 4332 ; // Number of pizza shops

int totalEmployees = 86928 ;  // Number of employees


double revenue = 390819.28 ;  // Revenue


Console.WriteLine("pizzaShops  "+ pizzaShops);

Console.WriteLine( "totalEmployees " +totalEmployees) ;
Console.WriteLine("revenue " +revenue ) ;

I have an answer:

pizzaShops 4332
totalEmployees 86928
revenue 390819.28

Why doesn’t the system skip further?
Did you use Console.WriteLine() to print pizzaShops ?

NEXT button is not active.

It turns out that the system needs this:
Console.WriteLine (pizzaShops);
Console.WriteLine (totalEmployees);
Console.WriteLine (revenue);

2 Likes

Console.WriteLine(pizzaShops);
Console.WriteLine(totalEmployees);
Console.WriteLine(revenue);

how to dot it in single line?? i mean code?

2 Likes

I get the point they’re trying to make with datatypes, but in reality financial operations tend to be int since it is a discreet number of cents.

I am stuck at the very first exercise.

The code:

int pizzaShops;
pizzaShops = 4332;

is not accepted, though perfectly legitimate (at least I think).

I’d love to understand what the error is.

1 Like

Why is the m after the number of a decimal necessary? The intro said it was to make it clear that we’re defining a decimal, but isn’t that why I’m writing decimal in front of the variable name in the first place? Oo

2 Likes

It’s because C# is a strongly typed language.

What is the use of the float data type?

While learning Unity they often use floats but I have yet to see a double.

This C# CodeAcademy course seems to suggest that doubles are more practical or better in some way but I know they take up a lot more space.

Wouldn’t it make more sense to use floats much more often than doubles to save space?

Wouldn’t…

Console.WriteLine($“Total pizza shops = {pizzaShops}. Total employees = {totalEmployees}. Total revenue = {revenue}.”);

be easier than writing 3 separate Console.WriteLine methods?

The lesson states that after giving a value to a decimal we need to include the letter “m” so C# knows we’re using a decimal, not a double. Why is this? Wouldn’t declaring the variable as a decimal already tell C# that it’s a decimal?

1 Like

Is there any reason why the data type decimal can say decimal revenue (no capitalization need for variable) but others like int need something like variableName (capitalization needed for variable)? I hope this question makes sense. Thanks!

I used this for the last part:

Console.WriteLine (pizzaShops);
Console.WriteLine (totalEmployees);
Console.WriteLine (revenue);

And in the console this shows up:

Program.cs(23,2): error CS1513: } expected [/home/ccuser/workspace/csharp-working-with-numbers-numerical-data-types-csharp/e2-workspace.csproj]

The build failed. Fix the build errors and run again.

The spelling is the same for my variables earlier on as is shown here. Does anyone here know what I’m doing wrong?

is your Revenue a double?

// Revenue
double revenue = 390819.28;

I believe I understand your question, and hopefully have an answer…
There is no law in the variable name that would stop the program running, it’s just a preferred policy for readability - called camelCase, the rule is the first word always starts with a lower case and the second is upper case, to differentiate two or more words. In the case of “revenue” it’s the first word so no capital needed (for example, if you wanted to call it total revenue, you’d use “totalRevenue”). As it’s not enforced, it’s entirely possible to write one of the previous variables how you want. Pizza shops could be written “PiZZaSHopS” or “PIZZA_Shops” for all C# cares).