A stored number becomes useful when the program calculates with it. An expression combines values and operators to produce another value. For example, 4 + 3 produces 7.
| Operator | Meaning |
|---|---|
+ | Add |
- | Subtract |
* | Multiply |
/ | Divide |
C++ evaluates multiplication and division before addition and subtraction. Parentheses group an expression so it is evaluated first. Compare these two calculations:
#include <iostream>
int main() {
int first = 4 + 3 * 2;
int second = (4 + 3) * 2;
std::cout << first << "\n";
std::cout << second << "\n";
return 0;
}
The first result is 10: multiply first, then add. The second is 14: add the grouped values, then multiply. Within the same precedence level, these arithmetic operators group from left to right. You do not need to memorize a large precedence table to write clear calculations; use parentheses when grouping helps explain the intent.
The starter supplies two sets of quantities. For cups, count the cups in all packs, then add the spares once. For chairs, find the combined chair count for one table before multiplying by the number of tables. That difference tells you where grouping matters. Replace the zero in each result declaration with an expression using the supplied names.
You are calculating quantities, not joining text. Keep the numbers unquoted and let the supplied output statements display the results. Use * for multiplication; a letter x is not C++'s multiplication operator.
cups with the pack count multiplied by cups per pack, plus the spare cups. The result should be Cups: 22.chairs by multiplying tables by the parenthesized sum of mainChairs and extraChairs. The result should be Chairs: 14.Edit main.cpp, press Run to inspect the Console, then Submit to check these results.