Constant Integers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adedoja

    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: }
  • Victor Bazarov

    #2
    Re: Constant Integers

    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


    Comment

    • Juha Nieminen

      #3
      Re: Constant Integers

      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.)

      Comment

      Working...