Thread: can someone help me debug this?

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    3

    can someone help me debug this?

    Code:
    #include<stdio.h>
    #define MONTH 12
    #define YEAR 2
    
    const char *month[]= {"January", "February", "March", "April", "May", "June", "July", 
                        "August", "September", "October", "November", "Decenmber"};
    
    int main() {
        
        int a[][MONTH] = {367, 654, 545, 556, 565, 526, 437, 389, 689, 554, 526, 625,
        429, 644, 586, 626, 652, 546, 449, 689, 597, 679, 696, 568};
        
        int i, j, yeartotal;
        double meanval;
        
        
        printf("%-10s%-10s\n", "Year", "Mean hit");
        printf("------------------\n");
        for(j= 0; j < MONTH; j++) {
            yeartotal= 0;
            for(i= 0; i < YEAR; i++) {
                yeartotal+= a[i][j];
            }
            meanval= (double)yeartotal/YEAR;
            printf("%-10s %8.2f\n", year[i], meanval);
        }
        
        return 0;
    }
    this is the error message:

    Code:
    ERROR: argument 2 of the function is undefined or not a valid expression
    ERROR: syntax error before or at line 25 in file C:\Users\Gabjew90\Desktop\hw7#10.c
      ==>:         printf("%-10s %8.2f\n", year[i], meanval);
      BUG:         printf("%-10s %8.2f\n", year<== ???
    ERROR: cannot execute command 'C:\Users\Gabjew90\Desktop\hw7#10.c'

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Where do you declare the array "year"?

    Ie the one you use here:
    Code:
    printf("&#37;-10s %8.2f\n", year[i], meanval);

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    3
    thanks it runs now but i changed year[i] to month[i] and here's the output: how do i correct it?

    Year Mean hit
    ------------------
    March 398.00
    March 649.00
    March 565.50
    March 591.00
    March 608.50
    March 536.00
    March 443.00
    March 539.00
    March 643.00
    March 616.50
    March 611.00
    March 596.50

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    In your outer loop, you are using variable j to iterate through the months. Perhaps anytime your want to see the month, you should use j instead of i.
    Mainframe assembler programmer by trade. C coder when I can.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary not built with debug info - why?
    By ulillillia in forum C Programming
    Replies: 15
    Last Post: 12-11-2008, 01:37 AM
  2. makefiles - debug & release?
    By cpjust in forum C Programming
    Replies: 6
    Last Post: 10-26-2007, 04:00 PM
  3. Debug --> Exceptions in Visual Studio 2005
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 08-10-2007, 02:12 AM
  4. Results in Debug and Release mode are different
    By jaro in forum C Programming
    Replies: 11
    Last Post: 05-27-2006, 11:08 AM
  5. Ask about Debug Assert Failed
    By ooosawaddee3 in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2002, 11:07 PM