can someone help me debug this?

This is a discussion on can someone help me debug this? within the C Programming forums, part of the General Programming Boards category; Code: #include<stdio.h> #define MONTH 12 #define YEAR 2 const char *month[]= {"January", "February", "March", "April", "May", "June", "July", "August", "September", ...

  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
    Katy, Texas
    Posts
    2,309
    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.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

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, 05:00 PM
  3. Debug --> Exceptions in Visual Studio 2005
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 08-10-2007, 03:12 AM
  4. Results in Debug and Release mode are different
    By jaro in forum C Programming
    Replies: 11
    Last Post: 05-27-2006, 12:08 PM
  5. Ask about Debug Assert Failed
    By ooosawaddee3 in forum C++ Programming
    Replies: 0
    Last Post: 04-25-2002, 12:07 AM

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