Thread: Why i can get the result print to the screen

  1. #1
    wise_ron wise_ron's Avatar
    Join Date
    May 2006
    Posts
    75

    Why i can get the result print to the screen

    Hi iam new to c programming and iam trying to compile this code in Dev C ++ 4.9.9.2 and it prints the result but when i compile it works but it closes the screen and i cant see the results.

    Thanks for your help


    Code:
    // Description: will ask the user for 2 numbers and print the even //numbers in between
    
    
    #include <stdio.h>
    int main()
    {
    int min, max, i;
    printf("Please enter the minimum number: ");
    scanf("%d", &min);
    printf("Please enter the maximum number: ");
    scanf("%d", &max);
    
    for (i=min; i<=max; i++)
    if (i%2 == 0)printf("%d\n", i);
    getchar(); // when you use Dev c ++
        return 0;
    }

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    20
    when I changed "getchar()" with a "getch()" or "scanf("%d");" your program waited after printing the result
    Last edited by mass; 05-22-2006 at 07:04 PM.

  3. #3
    Awesomefaceradcore bivhitscar's Avatar
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Posts
    210
    Code:
    system("PAUSE");
    return 0;
    Try adding that line and removing the last getchar() line.
    it's ironic considerate rarity patron of love higher knowledge engulfs me...

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    That's just your compiler. The second is blatantly incorrect, because you have no variable to scan into. You must have one, or use the "skip" specifier for scanf. The function getchar is an ANSI standard function, and should work on any compiler. The function getch is NOT a standard function, and only works on some compilers.

    There is a FAQ on the topic. Actually there are two of them.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Awesomefaceradcore bivhitscar's Avatar
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Posts
    210
    Quote Originally Posted by quzah
    The second is blatantly incorrect, because you have no variable to scan into.

    What were you referring to with this comment?

    [EDIT]

    Nevermind, I assume you were directing the comment at mass.
    it's ironic considerate rarity patron of love higher knowledge engulfs me...

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by bivhitscar
    What were you referring to with this comment?
    Quote Originally Posted by mass
    when I changed "getchar()" with a "getch()" or "scanf("%d");" your program waited after printing the result
    Which is why I mentioned scanf specifically in my reply.


    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    May 2006
    Posts
    20
    that was my scanf I think
    ok that was just an idea...

  8. #8
    wise_ron wise_ron's Avatar
    Join Date
    May 2006
    Posts
    75

    Thank you guys i got it

    Thanks bivhitscar and all you guys for your help. I apreciate it. Now it works.

    Wise_Ron

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Promblem with code
    By watchdogger in forum C Programming
    Replies: 18
    Last Post: 01-31-2009, 06:36 PM
  2. Can someone help with my seg fault?
    By John_L in forum C++ Programming
    Replies: 23
    Last Post: 03-01-2008, 04:04 PM
  3. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 12:51 PM
  4. plot a graph on the screen
    By dionys in forum C Programming
    Replies: 4
    Last Post: 04-15-2004, 02:46 PM
  5. Print Screen
    By /\/\ E /\/ @ in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 08-11-2002, 05:37 PM