Simple program...simple problem?

This is a discussion on Simple program...simple problem? within the C Programming forums, part of the General Programming Boards category; Don't know why but it dosent print out the right numbers, and prints out numbers that dont make any sence ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    29

    Simple program...simple problem?

    Don't know why but it dosent print out the right numbers, and prints out numbers that dont make any sence at all


    Code:
    #include <stdio.h>
    # define MAX 21
    int main(void){
    double Top_Temp,Right_Temp,Bottom_Temp , Left_Temp, Tolerance;
    int Grid_Colums,Grid_Rows, i,j,Iterations;
    double Log[MAX][MAX];
    
    
    printf("Enter the top side temp:");
    scanf("%lf",&Top_Temp);
    printf("Enter the right side temp:");
    scanf("%lf",&Right_Temp);
    printf("Enter the bottom side temp:");
    scanf("%lf",&Bottom_Temp);
    printf("Enter the left side temp:");
    scanf("%lf",&Left_Temp);
    
    printf("How many rows in the grid?");
    scanf("%i",&Grid_Rows);
    printf("How many columns in the grid?");
    scanf("%i",&Grid_Colums);
    
    
    
    printf("\n");
    printf("\n");
    printf("\n");
    printf("\n");
    printf("\n");
    
    
    
    
    ///preset all values to 0 or whatever the sides are
    for(i=1;i<=Grid_Colums;i++){
    for(j=1;j<=Grid_Rows;j++){
    if(j==1){
    Log[i][j]=Left_Temp;
    }
    else if(i==1 && j!=1 && j!=Grid_Rows){
    Log[i][j]=Top_Temp;
    }
    else if(j==Grid_Rows){
    Log[i][j]=Right_Temp;
    }
    else if(i==Grid_Colums && j!=1 && j!=Grid_Rows){
    Log[i][j]=Bottom_Temp;
    }
    else{
    Log[i][j]=0.0;
    }
    }
    }
    
    
    for(i=1;i<=Grid_Colums;i++){
    for(j=1;j<=Grid_Rows;j++){
    if(j==1){
    }
    else if(i==1 && j!=1 && j!=Grid_Rows){
    ///do nothing
    }
    else if(j==Grid_Rows){
    //do nothing
    }
    else if(i==Grid_Colums && j!=1 && j!=Grid_Rows){
    //do nothing
    }
    ///the avarege of all the spaces around the  the current space using (a+b+c+d+e+f+g+h+i)/9= average
    else{Log[i][j]=(((Log[1-i][1-j])+(Log[1-i][j])+(Log[1-i][1+j])+(Log[i][1-j])+(Log[i][j])+(Log[i][1+j])+(Log[1+i][1-j])+(Log[1+i][j])+(Log[1+i][1+j]))/9);
    }
    }
    }
    ///prints grid 
    for(i=1;i<=Grid_Colums;i++){
    for(j=1;j<=Grid_Rows;j++){
    printf("%8.2lf",Log[i][j],i,j);
    }
    }
    
    printf("\n");
    
    
    
    return 0;
    }
    here is an example of the out put

    Enter the top side temp:34
    Enter the right side temp:45
    Enter the bottom side temp:56
    Enter the left side temp:2
    How many rows in the grid?10
    How many columns in the grid?10





    2.00 34.00 34.00 34.00 34.00 34.00 34.00 34.00 34.00 45.00
    2.003846176819139386240495146280763901266114230000 00000000000000000000000000
    00000000000000000000000000000000000000000000000000 000000000000000000000000000000
    0000000.00 0.003951937901898015471105687508780148206111037000 0000000000000000
    00000000000000000000000000000000000000000000000000 000000000000000000000000000000
    00000000000000000.00395193790189801547110568750878 014820611103700000000000000000
    00000000000000000000000000000000000000000000000000 000000000000000000000000000000
    0000000000000000000.00 0.003786320267709942753891208951542362435293359000 0000
    00000000000000000000000000000000000000000000000000 000000000000000000000000000000
    00000000000000000000000000000.00773825675947454695 904703396065433099033889100000
    00000000000000000000000000000000000000000000000000 000000000000000000000000000000
    0000000000000000000000000000000.003951936491764604 692929035995985754708420099000
    00000000000000000000000000000000000000000000000000 000000000000000000000000000000
    000000000000000000000000000000000.00 45.00 2.00 0.00 0.00 0.00
    0.00 0.00 0.00 0.00 10.00 45.00 2.00 0.00 0.00 0.00
    0.00 0.00 0.00 0.00 10.00 45.00 2.00 0.00 0.00 0.00
    0.00 0.00 0.00 0.00 10.00 45.00 2.00 0.00 0.00 0.00
    0.00 0.00 0.00 0.00 10.00 45.00 2.00 0.00 0.00 0.00
    0.00 0.00 0.00 0.00 10.00 45.00 2.006185387601747340982356416560
    92461900413940200000000000000000000000000000000000 000000000000000000000000000000
    00000000000000000000000000000000000000000000000000 000000000000000000000000000000
    00000000000000000000000000000000000000000000000000 000000000000000000000000000000
    00000000000000000000000.00 0.00 0.00 0.00 0.00 0.00 0.00 10.
    00 45.00 2.006185387601747340982356416560924619004139402000 0000000000000000
    00000000000000000000000000000000000000000000000000 000000000000000000000000000000
    00000000000000000000000000000000000000000000000000 000000000000000000000000000000
    00000000000000000000000000000000000000000000000000 0000000000000000000.00 12.44
    12.44 12.44 12.44 12.44 12.44 16.22 45.00 2.00 56.00 56.00
    56.00 56.00 56.00 56.00 56.00 56.00 45.00
    Last edited by deadherorising; 03-12-2009 at 08:53 PM. Reason: stupid

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Have you printed out the values you input to verify that they have been set properly?

    A few print statements should do that. It will also verify that your scanf() and printf() format specifiers, are correct.

    Why are you working with array's at row and column 1, instead of 0? Are you trying to use a row or column as a buffer area or what?

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    29
    Thanks...it was simple...switched the 1-x to x-1 ohh ya failed at the fundimentals of mathamatics.
    i use one since it makes more sence to me...i always for get to count the zero, this way i dont forget.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. Running Program Problem
    By warfang in forum C++ Programming
    Replies: 10
    Last Post: 03-28-2007, 03:02 PM
  3. simple login program problem
    By suckss in forum C Programming
    Replies: 11
    Last Post: 11-11-2006, 05:02 PM
  4. Problem with a simple program
    By Salgat in forum C Programming
    Replies: 10
    Last Post: 06-15-2006, 06:57 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM

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