473,405 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Constant Integers

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: }
Feb 14 '08 #1
2 1554
Adedoja wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 14 '08 #2
Adedoja wrote:
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.)
Feb 15 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Kristian Bisgaard Lassen | last post by:
Hi, How do I parameterize a template by a a allocated array of integers, which is declared static and constant, so I can make compile time optimizations depending on the content of the array....
15
by: Alvin | last post by:
Hello, I have been experimenting with std::vector. Say I wanted to create a vector of integers but do not want the vector to change in size or capacity. In otherwords, it has a fixed number of...
5
by: Jeff | last post by:
Dim lngWeights as long, lngBuckets as Long Const STDWEIGHTS = 12 lngBuckets = 1000 lngWeights = lngBuckets * STDWEIGHTS This causes an Overflow error. For lower values it works. Obviously...
2
by: astro | last post by:
I want to get the numeric named constant value from an ini file. Basically I want to translate a string data type into the named constant value it represents. For example - for SQL-Server...
11
by: Mantorok Redgormor | last post by:
Is const really constant? And on an OT note: how can I post with a modified e-mail address so I don't get so much spam?
15
by: Scott | last post by:
Hi All, I have the following C code in a header file, outside of any functions: const float X = 50; const float Y = 100 * X; But, when compiling, I get an error: initializer element is...
22
by: Ben Finney | last post by:
Howdy all, I've recently packaged 'enum' in PyPI. In its description, I make the claim that it creates "immutable" enumeration objects, and that the enumeration values are "constant" values. ...
6
by: Amit Bhatia | last post by:
Hi, I am not sure if this belongs to this group. Anyway, my question is as follows: I have a list (STL list) whose elements are pairs of integers (STL pairs, say objects of class T). When I create...
1
by: hackerbob | last post by:
I'm trying to create a constant time event timer. Basically, a routine can set a callback to be called n ms from the current time, and the main event loop will wait until the delta between the...
34
by: jacob navia | last post by:
Hi I am adding an optimization to lcc-win: sqrt(2.0) will provoke now that the constant 1.4142... etc will be generated instead of generating an actual call. Details: -------
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.