# FAQ: Operators: Lesson - Mathematical Operations

This community-built FAQ covers the “Mathematical Operations” exercise from the lesson “Operators: Lesson”.

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

## FAQs on the exercise Mathematical Operations

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 () 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.

You can also find further discussion and get answers to your questions over in Language Help.

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

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Found a bug? Report it online, or post in Bug Reporting

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!

I had an issue with the last instruction.
My first thought was to use totalSalesValue = (booksSold * bookCost) / 2; to output the cut, and it ran as intended, yet the instruction told me that I was doing it wrong. I shortly appeased it afterwards.
A bit odd to see only one answer as correct for something like this.

2 Likes

what was your solution? my following code is throwing an error

#include <stdio.h>

int main() {

// Variables set for you, do not change here
int booksSold = 200;
double bookCost = 9.99;
double totalSalesValue;

totalSalesValue = booksSold * bookCost / 2;
totalSalesValue = totalSalesValue * .5;

// Output logic, no need to change this
printf("You sold %d books and your take home was \$%.2f\n", booksSold, totalSalesValue);
}

This was my solution.

#include <stdio.h>

int main() {

// Variables set for you, do not change here
int booksSold = 100 + 200;
double bookCost = 9.99;
double totalSalesValue;

totalSalesValue = (booksSold * bookCost);
totalSalesValue = totalSalesValue / 2;
// Output logic, no need to change this
printf("You sold %d books and your take home was \$%.2f\n", booksSold, totalSalesValue);
}

No idea how you get an error with your code, it works on my side.
But if it’s not letting you through to the next guide, I know why.
For one, it says you sold 200 MORE books, so it would be 100 + 200 instead of 200.
Plus, you simulated the publisher’s cut twice.

This is mine it always show error but the task show completed

#include <stdio.h> int main() { // Variables set for you, do not change here int booksSold = 100; double bookCost = 9.99; double totalSalesValue = booksSold * bookCost; // Make your changes here int booksSold = + 200; double totalSalesValue /= 2; // Output logic, no need to change this printf("You sold %d books and your take home was \$%.2f\n", booksSold, totalSalesValue); }

Here are a few issues to consider:

• In the block under the comment // Variables set for you, do not change here , three variables have been declared. At the time of declaration, you must specify the type of variable (int or double or some other type).
You can change values of variables, but once a variable has been declared, you can’t declare it again. In the block under the comment // Make your changes here, you have mentioned their types again. When making assignments, we shouldn’t specify their types again.
// Declaration and Initialization
int x = 7;

// Assignment after declaration

int x = 5; // Incorrect - int keyword should be omitted
// as we have already specified type in declaration.

x = 5; // Correct
• You have used incorrect syntax for addition assignment operator:
// You wrote:
int booksSold =  + 200;

// It should be:
booksSold += 200;
• After incrementing booksSold, you need to recalculate totalSalesValue. You calculated totalSalesValue when booksSold were 100. After additional sales, booksSold are 300, and totalSalesValue needs to be recalculated:
// You wrote:
int booksSold =  + 200;
double totalSalesValue /= 2;

// It should be:
booksSold +=  200;
totalSalesValue = booksSold * bookCost;
totalSalesValue /= 2;

If you fix all the issues, your final output should be:

"You sold 300 books and your take home was \$1498.50"

1 Like

Did I miss something or the symbols for multiplication and division weren’t shown but expected to be used?

If I wanted to store the value of updated booksSold variable in a different variable. Do I need to declare it first before carrying out the relevant process?

In the C programming language, you do need to declare variables before using them. However, the exact declaration depends on the context and the scope of the variables. Here’s an example:

#include <stdio.h>

int main() {
// Original value of booksSold
int booksSold = 100;

// Declare a new variable to store the updated value
int updatedBooksSold;  // You can initialize it with some default value or leave it uninitialized

// Perform some operation to update booksSold
// For example, let's say you increase the sales by 10
booksSold += 10;

// Store the updated value in the new variable
updatedBooksSold = booksSold;

return 0;
}