Lecture #7
Lecture #7
PROBLEM SOLVING
(FALL 2022-23)
Lecture 7
REVISION
2
USING VARIABLES, CONSTANTS,
ASSIGNMENTS, PROGRAM
u Cay Horstmann:
§ Chapter 2: Sections 2.1-2.2
Variable Names
1. Variable names must start with a letter or the underscore
(_) character, and the remaining characters must be
letters numbers, or underscores.
2. You cannot use other symbols such as $ or %. Spaces
are not permitted inside names; you can use an
underscore instead, as in can_volume.
3. Variable names are case-sensitive, that is, can_volume
and can_Volume are different names.
For that reason, it is a good idea to use only lowercase
letters in variable names.
4. You cannot use reserved words such as double or
return as names; these words are reserved exclusively
for their special C++ meanings.
C++ for Everyone by Cay Horstmann
Copyright © 2012 by John Wiley & Sons. All rights reserved
Variable Names
u Note:
§ % is Mod (Modulo, Modulus): the remainder
§ Integer division is different from floating
point (normal) division
or
In a + b / 2,
the b / 2 happens first.
Ø Use parenthesis!
(-(b * b - 4 * a * c) / (2 * a)
pow(base, exponent)
b + pow(1 + r / 100, n)