Constants and Declarations

I have this hw problem. This is an example of one of the seven I need. Am I declaring the double symbolic constant right? "The program should use at least seven symbolic constants. They should be:
a double that represents the per check fee for fewer than 20 checks (0.10)."
This is what I have for this particular question. The second is obviously a different fee. I just want to make sure I'm starting this out right before I start typing the entire code I need.

1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <iomanip>

using namespace std;

int main()
    // Symbolic Constants Declarations
{
    const double checkFee = 0.10;
    const double checkFee2 = 0.08;
Yes that is correct syntax. If you want your constant doubles to be true globals, declare them right above main, and I would preferably write the names using capslock, just so you know they're constant variables, and not function prototypes.
@ndfan2015 you are correct.

@YTGHNG I think you are confusing constants with macro definitions:

1
2
3
#define THIS_IS_A_MACRO 0.10

const double thisIsAConst = 0.10;

Last edited on
No, I am familiar with macros. I don't like macros because if you're defining a function as such, depending on the compiler, they might do weird and undesirable things with order of operations. So I usually have something like
1
2
3
4
5
6
const <typedef> OBJECT_NAME = <somevalue>;

someFunction()
{
//etc...
}

because to me, it's very clear what I'm going to use it for. But maybe it's just dependent on the goal of the project. And programmer preference.

Ah, I see.

And yes, although you can do quite powerful things with the preprocessor, I must agree with you that macro-laden code can be truly horrible to both read & debug.
Topic archived. No new replies allowed.