problem with printf!!!!

This is a discussion on problem with printf!!!! within the C++ Programming forums, part of the General Programming Boards category; Hello everybody, see this program Code: #include<stdlib> #include<stdio> #include<conio> #include<iostream> using namespace std; int main() { int l; double x; ...

  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
    21,931
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,931
    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().
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,931
    but instead of getch(), tell me what to use?
    How to keep a Windows console from closing.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 05:16 PM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM

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