Thread: int array isn't storing proper values.

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    163

    int array isn't storing proper values.

    This is my code, I stripped it down to make it easier to help.

    Code:
    #include <iostream>
    
    using namespace std;
    
    void showTemps(int[], int);
    
    int main()
    {
        int temp[10] = {32, 24, 29, 41, 60, 
                        67, 78, 88, 93, 102};
        int date[10] = {010106 , 012506 , 022006 , 031206 , 040706 , 042706 , 051506 , 060106 , 062706 , 072506};
                   
                        
        int inputDate = 0;
        int counter = 0;
        
        cout << "Please input date(mmddyy): ";
        cin >> inputDate;
        
        showTemps(date, 10);
        cin >> inputDate;
        return 0;
    }
    
    void showTemps(int nums[], int size)
    {
         for (int index = 0; index < size; index++)
             cout << nums[index] << endl;
    }
    so, it should output the numbers in the date array, right?
    THis is what I get:
    4166
    5446
    9222
    12934
    16838
    17862
    21318
    24646
    26054
    30022

    Also, it got upset with certain numbers when I was trying to put them into the array. such as 012906 wouldn't work, while 012506 will.
    Last edited by System_159; 08-31-2006 at 08:57 AM.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
    010106
    Numbers prefixed with 0 in C and C++ are octal numbers. And you can't store a leading zero in any case. The best way to store something like that is to use a string.

    [edit] And to keep your console open, read this FAQ:
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    which directs you to
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  3. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 09:16 PM
  4. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM