Thread: a strange problem, hard to solve too

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    72

    Angry a strange problem, hard to solve too

    hi everyone,
    i'm a new computer engineer and C is among the beginning courses.
    anyway i put the first program source code in my software which is "dev c++ version 4.9.9.2" under windows pro 5.1
    the source is:
    Code:
    #include<stdio.h>
    main()
    { 
          printf(" hello world");
          return(0);
    }
    the problem is that when i run this program
    it opens and closes quickly like a flash so i couldn't look at what is written in it.
    please help me as soon as possible. thanks a lot

  2. #2

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    145
    Sure is a tough one to solve.

  4. #4
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121
    dude... the program already ran, run it in DOS and you will see, or put something like
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
         printf("hello world\n");
         system("pause");
         return (0);
    }
    try that and you will be able to see the words
    -- Will you show me how to c++?

  5. #5
    Registered User
    Join Date
    Dec 2005
    Location
    Australia - Melbourne
    Posts
    63
    "hard to solve" sure got my attention.

    i had the exact same problem when i first looked into c.

  6. #6
    Matt Conway bobthebullet990's Avatar
    Join Date
    Nov 2005
    Location
    Cambridge
    Posts
    122
    yes... and me also!!! i remember that problem!!! ...a simple scanf() sorts it out! ...either that or just run it on linux and output is on the shell!!! far easier!
    Many junglists take pride in their belongin to what may be referred to as a globalised drum & bass subculture, as a subculture though, it is not nearly as distinct at gothic or punk!

  7. #7
    Registered User
    Join Date
    Jan 2007
    Posts
    72
    thanks a lot friends but how can we do that if we have a program that holds "if" statments wouldn't be harder work or it's going to be a simple stuff

  8. #8
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    why making it so complicated. just place a standard function getchar before the return statment. It just solves the problem. Look the sample code

    Code:
    #include <stdio.h>
    
    int main()
    {
        printf("Hello World\n");
        
        getchar();
        return 0;
    }
    And read the FAQ. About this. And system("PAUSE"); Wouldn't be a good idea cos it has to trap to OS and it not portable. Works only on windows machince and take too much processing time.

    ssharish2005

  9. #9
    Registered User
    Join Date
    Jan 2007
    Posts
    72
    thanks a lot friends and experts i'm very happy to be a part of this science community. anyway
    this is a code that i have made
    Code:
    #include<stdio.h>
    #include<math.h>
    #include<stdlib.h>
    main(void)
    {
          double a,b,c,d,X1,X2;
          printf(" this program can solve equations of degree two");
          printf("\n this kind of equations has this format ax˛+bx+c=0");
          printf("\n so you have to know the entegers a,b,c before the beginning");
          printf("\n please enter the digit a:");
          scanf("%lf",&a);
          printf("\n please enter the digit b:");
          scanf("%lf",&b);
          printf("\n please enter the digit c:");
          scanf("%lf",&c);
          d = (b*b)-(4*a*c);
          printf(" this is delta of the equation: %f",d); 
    
          if (d < 0);
          printf("\nthis equation doesn't have any solution\n");
          system("pause");
          if(d > 0);
          printf("\nthis equation accept a solution\n");
          X1=(-b-(sqrt(d)))/(2*a);
          X2=(-b+(sqrt(d)))/(2*a);
          system("pause");
          printf("The solution is X1=%f and X2=%f",X1,X2);
          system("pause");
    this is the code please help me editing it. thanks a lot

  10. #10
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Code:
    #include<stdio.h>
    #include<math.h>
    #include<stdlib.h>
    
    int main()
    {
          double a,b,c,d,X1,X2;
          
          printf(" this program can solve equations of degree two");
          printf("\n this kind of equations has this format ax&#178;+bx+c=0");
          printf("\n so you have to know the entegers a,b,c before the beginning");
          printf("\n please enter the digit a:");
          scanf("%lf",&a);
          
          printf("\n please enter the digit b:");
          scanf("%lf",&b);
          
          printf("\n please enter the digit c:");
          scanf("%lf",&c);
          d = (b*b)-(4*a*c);
          
          printf(" this is delta of the equation: %f",d); 
    
          if (d < 0)
          {
                printf("\nthis equation doesn't have any solution\n");
                getchar();
          } 
             
          if(d > 0)
          {
                printf("\nthis equation accept a solution\n");
                X1=(-b-(sqrt(d)))/(2.0*a);
                X2=(-b+(sqrt(d)))/(2.0*a);
                printf("The solution is X1=%f and X2=%f",X1,X2);
                getchar();
          }    
    
          return 0;
    }
    Point out the differeces and post again

    ssharish2005

  11. #11
    Registered User
    Join Date
    Jan 2007
    Posts
    72
    thanks a lot a lot a lot now i can program thank you friends.


    NB: you forgot to put the function getchar(); after the first ""printf(" this is delta of the equation: %f",d); "" i mean before the first if

  12. #12
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    a,b,c are numbers not digits

    getchar(); better take out of the if - put just before return

    when d ==0 where is just 1 root

    "a" should be cheched to be not 0 - other wise you get the crash
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  13. #13
    Registered User
    Join Date
    Jan 2007
    Posts
    72
    thanks a lot

  14. #14
    Registered User
    Join Date
    Jun 2004
    Posts
    201
    Quote Originally Posted by ssharish2005
    why making it so complicated. just place a standard function getchar before the return statment. It just solves the problem. Look the sample code

    Code:
    #include <stdio.h>
    
    int main()
    {
        printf("Hello World\n");
        
        getchar();
        return 0;
    }
    And read the FAQ. About this. And system("PAUSE"); Wouldn't be a good idea cos it has to trap to OS and it not portable. Works only on windows machince and take too much processing time.

    ssharish2005
    dont make suggestions about making the program wait. If you are developing a console program on MSVC for instance you fire up the program and it adds the wait for you. So when adding a manual wait you got 2 waits suddenly. Just fire up the damn program from a console!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. Replies: 2
    Last Post: 04-25-2005, 11:59 AM
  3. Strange problem with bmp
    By Victor in forum Linux Programming
    Replies: 2
    Last Post: 04-04-2005, 02:48 PM
  4. strange problem - string manipulation [fixed]
    By Spitball in forum C++ Programming
    Replies: 1
    Last Post: 01-09-2005, 08:26 AM
  5. Strange file problem.
    By tilex in forum C++ Programming
    Replies: 1
    Last Post: 12-29-2004, 12:32 AM