Constant Integers

A

Adedoja

I will like to know if this program is acceptable. Infact Iam not a C+
+ programmer, Iam an old student with old language, but Iam doing fine
to work on any language. My program is this:

1: #include <iostream>
2: int main()
3:{
4: const int sunday = 0;
5: const int monday = 1;
6: const int tuesday = 2;
7: const int wednesday = 3;
8: const int thursday = 4;
9: const int friday = 5;
10 const int saturday = 6;
11:
12: int today
13: today = monday;
14:
15: if (today == sunday
16: today == saturday
17: std::cout << "\ngotta' Love the weekends!\n";
18: else
19: std::cout << "\nback to work.\n";
20:
21: return 0;
22: }
 
V

Victor Bazarov

Adedoja said:
I will like to know if this program is acceptable.

The easiest way to get the first approximation is to run it through
a compiler. Have you attempted that? If yes, what were the results?
If not, why?
Infact Iam not a
C+ + programmer,

Just a note: there is no space between pluses in C++.
Iam an old student with old language, but Iam doing
fine to work on any language. My program is this:

1: #include <iostream>
2: int main()
3:{
4: const int sunday = 0;
5: const int monday = 1;
6: const int tuesday = 2;
7: const int wednesday = 3;
8: const int thursday = 4;
9: const int friday = 5;
10 const int saturday = 6;
11:
12: int today
13: today = monday;
14:
15: if (today == sunday
16: today == saturday
17: std::cout << "\ngotta' Love the weekends!\n";
18: else
19: std::cout << "\nback to work.\n";
20:
21: return 0;
22: }

The program contains a few syntax errors. Let your compiler point
them out to you.

V
 
J

Juha Nieminen

Adedoja said:
4: const int sunday = 0;
5: const int monday = 1;
6: const int tuesday = 2;
7: const int wednesday = 3;
8: const int thursday = 4;
9: const int friday = 5;
10 const int saturday = 6;
11:
12: int today
13: today = monday;

You might consider this alternative:

enum WeekDay
{ sunday, monday, tuesday, wednesday, thursday, friday, saturday };

WeekDay today = monday;

Besides being shorter, it has other advantages, such as the compiler
complaining if you try to use an invalid value in a variable if type
WeekDay.

(Btw, it's usually a good idea to distinguish the names of constants
from regular variable names. Which notation you use is a question of
taste, mostly. Some people use all-caps, others use hungarian notation,
others use something else.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top