Thread: problem with printf!!!!

  1. #1
    Registered User
    Join Date
    Apr 2008
    Location
    Barranquilla-Colombia
    Posts
    21

    Question problem with printf!!!!

    Hello everybody,
    see this program
    Code:
    #include<stdlib>
    #include<stdio>
    #include<conio>
    #include<iostream>
    
    using namespace std;
    int main()
     {
       int l;
       double x;
       float u[11][11];
       h=1.0/4.0 ;
       for (l=0; l<11;l++)
        {
          x=l*h;
          u[l][0]=1.0;
          printf("u=  %6.4f\n",u[l][0]); //line *
          printf("  %d    %d    %6.4f   %6.4f    %6.4f     \n",l,0,x,0,u[l][0]); //line **
        }
       getch();
     }//end program
    the problem is that in the line *, puts the right value of u[l][0], it is one (1.0), but in the next line **, puts the value of u[l][0] as zero (0).

    the problem is using printf?
    Any suggest?

    Bye Miguel.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I think you are just looking at the wrong column.

    Anyway, note that your code should not even compile since <stdlib> should be <cstdlib>, <stdio> should be <cstdio>, <conio> should be <conio.h> but actually is not even needed as getch() can be replaced, and then h is not declared.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2008
    Location
    Barranquilla-Colombia
    Posts
    21
    well, i'm working with Borland C++, it is not necessary to write ".h" at the end.
    About the others libraries, i do not use for the moment.
    I just took part of a program and posted it.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    In any case, you are just looking at the wrong column.

    If you disagree, post the smallest and simplest compilable code that demonstrates the problem. Oh, and do not use the Borland specific <conio>, and that means do not use getch().
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Apr 2008
    Location
    Barranquilla-Colombia
    Posts
    21
    o.k
    but instead of getch(), tell me what to use?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    but instead of getch(), tell me what to use?
    How to keep a Windows console from closing.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Apr 2008
    Location
    Barranquilla-Colombia
    Posts
    21
    i solved the problem,
    thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems reading entered race times C
    By loopymoo26 in forum C Programming
    Replies: 12
    Last Post: 05-23-2009, 07:38 AM
  2. Help with a C Programing Quiz project
    By dilemma in forum C Programming
    Replies: 12
    Last Post: 05-15-2009, 03:35 PM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. error in program????
    By SpEkTrE in forum C Programming
    Replies: 5
    Last Post: 11-24-2003, 06:16 PM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM