can someone proof read this for me?

This is a discussion on can someone proof read this for me? within the C Programming forums, part of the General Programming Boards category; this is pretty stupid, but it bothers me. when i a.out, this is what i get: Here is Homework 7: ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    8

    can someone proof read this for me?

    this is pretty stupid, but it bothers me. when i a.out, this is what i get:

    Here is Homework 7:
    Month 0: x[] = { 0.200 0.300 0.500} <-------
    Month 1: x[] = { 0.270 0.380 0.350 }
    Month 2: x[] = { 0.327 0.398 0.275 }
    Month 3: x[] = { 0.369 0.394 0.238 }
    Month 4: x[] = { 0.397 0.384 0.219 }
    Month 5: x[] = { 0.417 0.374 0.209 }
    Month 6: x[] = { 0.429 0.366 0.205 }
    Month 7: x[] = { 0.437 0.361 0.202 }
    Month 8: x[] = { 0.442 0.357 0.201 }
    Month 9: x[] = { 0.445 0.354 0.201 }
    Month 10: x[] = { 0.447 0.353 0.200 }
    Month 11: x[] = { 0.448 0.352 0.200 }
    Month 12: x[] = { 0.449 0.351 0.200 }

    as you can see where the arrow is, all of the lines have a space between the last number and the } except month 0. why?

    here's my code:

    Code:
    #include <stdio.h>
    void prob1(void);
    int main(void)
    {
            prob1();
            exit(0);
    }
    void prob1(void)
    {
            double a[3][3]={0.8, 0.2, 0.1,
                            0.1, 0.7, 0.3,
                            0.1, 0.1, 0.6};
            double x0[3]={0.2, 0.3, 0.5 }, x1[3];
            double sum;
            int month, row, col, rows=3, cols=3;
            printf("\nHere is Homework 7:\n");
            printf("Month %2d: x[] = {", 0);
            for(row=0; row<rows; row++) printf(" %6.3f", x0[row]);
            printf("}\n");
            for(month=1; month<=12; month++ ){
                    printf("Month %2d: x[] = {", month);
                    for(row=0; row<rows; row++){
                    for(col=0, sum=0.0; col<cols; col++){
                            sum += a[row][col]*x0[col];
    }
    x1[row] = sum;
    }
            for(row=0; row<rows; row++) printf(" %6.3f", x1[row]);
            printf(" }\n");
            for(row=0; row<rows; row++) x0[row] = x1[row];
    }
    printf("\n");
    
            return;
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >printf("}\n");
    I'd say that's your culprit.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What Would You Use To Read User Input?
    By djwicks in forum C Programming
    Replies: 11
    Last Post: 04-05-2005, 03:32 PM
  2. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  3. I am lost on how to read from file and output to file?
    By vicvic2477 in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2005, 10:52 AM
  4. Read Array pro!!Plz help!!
    By Supra in forum C Programming
    Replies: 2
    Last Post: 03-04-2002, 02:49 PM
  5. Help! Can't read decimal number
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 09-07-2001, 02:09 AM

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