expected primary expression before "." token

This is a discussion on expected primary expression before "." token within the C++ Programming forums, part of the General Programming Boards category; Hi there, I'm trying to do a program that allows user to enter a number between 1-365 and convert that ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    4

    expected primary expression before "." token

    Hi there, I'm trying to do a program that allows user to enter a number between 1-365 and convert that to month and day (for example, 32 -> Feb. 1st). I tried compiling the program but I got "expected primary expression before '.' token" in int main(). I can't seem to figure out what I did wrong. If any of you can just point me in the right direction, that'll be awesome. Thank you so much!

    Code:
    //This program is for chapter 14 - review question 2 - Day of the year
    
    #include <iostream>
    #include <string>
    using namespace std;
    
    class DayOfYear
    {
          private:
                 static const int daysAtEnd[];
                 static const int monthNames[];
          public:
                 
    
    void DayOfYear::print()
    {
         int month = 0;
         int day;
         
         while (daysAtEnd[month] < day)
         month = (month+1)%12;
         if (month == 0)
         cout << "January" << day;
         else
         {
             cout << DayOfYear::monthNames[month]<< " "
             <<day - DayOfYear::monthNames[month-1];
         }
    }
    
    void DayOfYear::setNumber(int n)
    {
         int number;
         if (n >= 0 && n <= 365)
         number=n;
         else
         {
             cout << n << "is not a valid"
             << "value for the month.\n";
             exit (EXIT_FAILURE);
         }
    }
    
    };
    
    int daysAtEnd[12] = {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
    char monthNames[] = "January, February, March, April, May, June, July, August, September, October, November, December";
       
    int main()
    { 
        
    DayOfYear.print(); <--- expected primary expression before "." token
    
    
    system("PAUSE");
    return 0;
    }
    thanks!!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,888
    At a glance, you need a DayOfYear object. Beyond that, you might want to switch books, perhaps based on the recommendations in What is the best book for a beginner to learn c++, if that code was from a beginners' book. It appears to be teaching the use of classes where the class is used rather poorly.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jul 2007
    Location
    Kansas, USA
    Posts
    12
    Basically, the DayOfYear class is like a cookie cutter, you need to make some cookies with the cutter before you can do anything.

    Code:
    //doy is the object or the "cookie" in the above analogy.
    DayOfYear doy;
    
    // calls the print method
    doy.print();
    Last edited by aprescott_27; 07-10-2007 at 02:51 PM. Reason: Code tags

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    2,050
    There are a lot of things that are done poorly in that program. You should get a good book if you want to lean C.

    What exactly do you want DayOfYear.print() to do?
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  5. #5
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503

    Talking

    Quote Originally Posted by aprescott_27 View Post
    Basically, the DayOfYear class is like a cookie cutter, you need to make some cookies with the cutter before you can do anything.
    You blew the analogy at the end. You should had said "the DayOfYear class is like a cookie cutter, you need to make some cookies with the cutter before you can eat them."

    Especially since using an object is often referred to as "consuming" them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21