Like Tree1Likes
  • 1 Post By jimblumberg

Illigeal digits 08 & 09...why?

This is a discussion on Illigeal digits 08 & 09...why? within the C++ Programming forums, part of the General Programming Boards category; I am in the process of self-teaching C++ using a complex Lotto Program for exercise work. I keep getting an ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Location
    Florida, Dade County, Homestrad, 33031
    Posts
    40

    Illigeal digits 08 & 09...why?

    I am in the process of self-teaching C++ using a complex Lotto Program for exercise work. I keep getting an error in one section stating that I've used an illegal digit "08" & "09" and I do not know why. My program is:


    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <ios>
    #include <algorithm>
    
    using namespace std;
    
    int main ()
    {
     
    
     
    /* =========================================================================================================================== */ 
    
    Start:
    
     char z;
     
     cout << "For Florida MegaMillion press #1" << endl << endl;
     cout << "For Florida Lotto press #2" << endl << endl;
     cout << "For National Power-Ball press #3"  << endl << endl;
     cout << "To start over press #4" << endl << endl;
     cin >> z;
     
     if (z == 1)
         {
           cout << "You have chosen to play Florida's MegaMillion Lotto," << endl << endl;
            goto MegaMillion;
        }
    
     else
    
     if (z == 2)
         {
           cout << "You have chosen to play the Florida Lotto." << endl << endl;
            goto FloridaLotto;
        }
    
     else
    
     if (z == 3)
        {
           cout << "You have chosen to play the National Power-Ball Lotto," << endl << endl;
            goto PowerBall;
        }
    
     else
    
     if (z == 4) goto Start;
    
     else
    
     if (z != 1 && z != 2 && z != 3 && z != 4)
        {
            cout << "You have chosen to end the program." << endl << endl;
           return 0;
        } 
    
    /* ================================================================================================================================*/
    
    
    MegaMillion:
    
    char x;
    char str [6];
    
    #define Anydate();    // Declare / define the variable Anydate.
    #define date
    #define number
    
    
    /*
       {
        Anydate();
        Anydate(string,[6]);
        ~Anydate();
        string date;
        int number[6];
       };
    
        
        Anydate=Anydate(string thatdate, int thatnumber[6]);
    
      
       {
        date=thatdate;
        for(int i=0;i!=6;i++);
        number[i]=thatnumber[i];
       }
    
    
        Anydate=Anydate();
        
    
    
        Anydate=~Anydate();
    
    */
    
     
        // initialize 44 variables to receive and count the numbers from 1 thru 44
    
    int n01=0; int n02=0; int n03=0; int n04=0; int n05=0; int n06=0; int n07=0; int n08=0; int n09=0; int n10=0; int n11=0; int n12=0;
    int n13=0; int n14=0; int n15=0; int n16=0; int n17=0; int n18=0; int n19=0; int n20=0; int n21=0; int n22=0; int n23=0; int n24=0;
    int n25=0; int n26=0; int n27=0; int n28=0; int n29=0; int n30=0; int n31=0; int n32=0; int n33=0; int n34=0; int n35=0; int n36=0;
    int n37=0; int n38=0; int n39=0; int n40=0; int n41=0; int n42=0; int n43=0; int n44=0;
    
    
       ifstream a_file ( "D:\ LotteryProgram / MegaMill" );   //Opens MegaMill for reading the file
    
       a_file >> str;    //Reads one string from the file MegaMill
    
    
    
       ofstream b_file ( "D:\ LotteryPrograms/ MegaNum" ); //Creates an instance of ofstream, and opens the file MegaNum.
    
       b_file << "Anydate";  // Outputs to MegaNum through b_file.
    
       b_file << "x";
    
       b_file.close();   // Close the file stream explicitly.
    
      
    
    
     
    
    { 
     if (x == 01) n01++; if (x == 02) n02++; if (x == 03) n03++; if (x == 04) n04++; if (x == 05) n05++; if (x == 06) n06++; if (x == 07) n07++;
     if (x == 08) n08++; if (x == 09) n09++; if (x == 10) n10++; if (x == 11) n11++; if (x == 12) n12++; if (x == 13) n13++; if (x == 14) n14++;
     if (x == 15) n15++; if (x == 16) n16++; if (x == 17) n17++; if (x == 18) n18++; if (x == 19) n19++; if (x == 20) n20++; if (x == 21) n21++;
     if (x == 22) n22++; if (x == 23) n23++; if (x == 24) n24++; if (x == 25) n25++; if (x == 26) n26++; if (x == 27) n27++; if (x == 28) n28++;
     if (x == 29) n29++; if (x == 30) n30++; if (x == 31) n31++; if (x == 32) n32++; if (x == 33) n33++; if (x == 34) n34++; if (x == 35) n35++;
     if (x == 36) n36++; if (x == 37) n37++; if (x == 38) n38++; if (x == 39) n39++; if (x == 40) n40++; if (x == 41) n41++; if (x == 42) n42++;
     if (x == 43) n43++; if (x == 44) n44++;
    }
    
    
    // This is where I'm getting illegal 08 & 09 digits... why?
      
     /* ================================================================================================================================== */
    
    
    FloridaLotto:
    
    char u;
     
      cout << "This part works just fine" << endl << endl << "Press 'y' to continue"  << endl << endl << "Press 'n' to exit program";
    
    cin >> u;
    
        if (u == 'y')
    
          { cout << "You have chosen to start over again";
            goto Start;
          }
    
        if (u == 'n') 
    
        {
           cout << "You have chosen to end the program." << endl << endl;
           return 0;
        } 
    
         if (u != 'y' && u != 'n')
        
        {    
    
           cout << "Hey dummy, What part of 'y' or 'n' did you fail to understand?" << endl << endl;
           goto Start;
        }
    
     /* =========================================================================================================================== */
    
    
      PowerBall:
    
    
         char m;
     
          cout << "This part works just fine" << endl << endl << "Press 'y' to continue"  << endl << endl << "Press 'n' to exit program";
    
        cin >> m;
    
        if (m == 'y')
    
          { cout << "You have chosen to start over again";
            goto Start;
          }
    
        if (m == 'n') 
    
        {
           cout << "You have chosen to end the program." << endl << endl;
           return 0;
        } 
    
         if (m != 'y' && m != 'n')
        
        {    
    
           cout << "Hey dummy, What part of 'y' or 'n' did you fail to understand?" << endl << endl;
           goto Start;
     
        }
    
    
        return 0;
    
       }

  2. #2
    Registered User
    Join Date
    Mar 2012
    Posts
    14
    Can you give the exact error you are getting? Is it a compile, link or runtime error?

    Why use goto statements instead of making the various routines into functions? As is, you may run into errors because you re-declare some variables. For example, suppose you choose "1" for Florida Lotto, then choose anything other than "n", then choose "1" for Florida Lotto again. You'll hit line 147 again, which should cause an error.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    2,674
    Remove the zeros that you have before your constants, the leading zero signifies that the number is in octal format, and some of your values are not correct octal numbers. Also loose the goto statements.

    Jim
    Salem likes this.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,157
    Quote Originally Posted by Therry View Post
    Code:
     if (x == 01) n01++; if (x == 02) n02++; if (x == 03) n03++; if (x == 04) n04++; if (x == 05) n05++; if (x == 06) n06++; if (x == 07) n07++;
     if (x == 08) n08++; if (x == 09) n09++; if (x == 10) n10++; if (x == 11) n11++; if (x == 12) n12++; if (x == 13) n13++; if (x == 14) n14++;
    
    // This is where I'm getting illegal 08 & 09 digits... why?
    You wasted folks time wading through a bunch of irrelevant code, when you could have just extracted the parts relevant to your problem. Why???

    In any event, to answer your question, a literal integral value with a leading zero (for example, 07) is interpreted as an octal (base 8) value. For example 011 (octal) actually has the value of 9 (in decimal).

    An octal value is base 8. So digits with the value 8 or more are illegal. The solution is to remove the leading zeros.


    Note, if the literal value has a leading "0x" (a zero followed by an x character) it is hexadecimal (base 16). So 0-9 and A-E are acceptable. And 0x11 is actually a representation of the value 17.
    Right 98% of the time, and don't care about the other 3%.

  5. #5
    Registered User
    Join Date
    Mar 2012
    Posts
    14
    Quote Originally Posted by jimblumberg View Post
    the leading zero signifies that the number is in octal format
    Huh. Learn something new every day. I knew a 0x prefix meant hexadecimal, but didn't realize octal was also implemented similarly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help on sum digits in C
    By KevinH123 in forum C Programming
    Replies: 7
    Last Post: 12-07-2010, 12:36 AM
  2. how to add 2 digits?
    By nefsan in forum C Programming
    Replies: 16
    Last Post: 03-28-2008, 02:41 PM
  3. Digits...
    By Murk in forum C Programming
    Replies: 8
    Last Post: 02-05-2008, 01:16 PM
  4. 100,000 digits of pi
    By The Brain in forum A Brief History of Cprogramming.com
    Replies: 102
    Last Post: 11-23-2004, 11:31 PM
  5. Getting digits from int.
    By aker_y3k in forum C++ Programming
    Replies: 8
    Last Post: 02-21-2003, 11:45 AM

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