Thread: Help

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    25

    Exclamation Help

    ok so im very new to programming in c and i have this program called "Open Watcom", or "Miracle C" that i use for my c

    anyways to the point, when it comes to running the program, it runs it for the inputs, but when it gives the answer it closes itself

    so what im asking is, how do i do to stop the screen from closing itself, so that i could see the answer, here is my program just in case

    Code:
    #include <stdio.h>
    #include <math.h>
    
    int main()
    {
    double t,temp,te,min,hr;
    printf("how many hours since power failure: ");
    scanf("%f",&te);
    printf("how many minutes since power failure: ");
    scanf("%f",&t);
    min=t/60;
    hr=min+te;
    temp=((4*(hr*hr))/(hr+2))-20;
    
    printf("The temperature after %f hour/s and %f minutes is at (celsius) %f",te,t,temp);
    }

  2. #2
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    #include<stdlib.h>


    and add the line
    Code:
    system("pause");
    return 0;
    after the last printf.


    or use VS2008 express.

  3. #3
    Beautiful to C Aia's Avatar
    Join Date
    Jun 2007
    Posts
    124
    Quote Originally Posted by abk View Post
    #include<stdlib.h>


    and add the line
    Code:
    system("pause");
    return 0;
    after the last printf.


    or use VS2008 express.
    How about just a simple getchar(); as the last statement?
    I like that one best. It is portable and it will train you to not leave any characters in the standard input stream.
    When the eagles are silent, the parrots begin to jabber. ~Winston Churchill

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    25
    Quote Originally Posted by abk View Post
    #include<stdlib.h>


    and add the line
    Code:
    system("pause");
    return 0;
    after the last printf.


    or use VS2008 express.
    thanks, now i only have one last question i want the program to end after i hit a key and not repeat itself

  5. #5
    Registered User
    Join Date
    Feb 2008
    Posts
    25

    Cool

    Quote Originally Posted by Aia View Post
    How about just a simple getchar(); as the last statement?
    I like that one best. It is portable and it will train you to not leave any characters in the standard input stream.
    ohhh there we go i got it thanks, this one closes at the end, thanks alot guys made my day

  6. #6
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    Quote Originally Posted by dals2002 View Post
    thanks, now i only have one last question i want the program to end after i hit a key and not repeat itself
    I don't know why its repeating itself. But it works for me and many more people.


    Yes, i agree with Aia. getchar() is better.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by dals2002 View Post
    ok so im very new to programming in c and i have this program called "Open Watcom", or "Miracle C" that i use for my c
    Wait. So you're using Miracle C as your compiler???
    If you do, then I suggest you get on with the times.
    http://cpwiki.sourceforge.net/Integr...nt_Environment
    Pick a different IDE. Visual Studio is a good one.

    You should also learn indentation.
    It's very important.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed