Thread: Very simple question

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    244

    Very simple question

    Hello,
    I was wondering if someone can tell me how I could make the "Press any key to continue...." not appear on my screen when I run my program, or if thats not possible is there a way that I can shift it down with a "\n" because I haven't found a way yet, and it is a bit annoying at times


    For example if you compile and run the code below after the last printout of the program it says "Press any key to continue..." and thats what I am trying to either move or get rid of if possible.

    Code:
    #include <stdio.h>
    
    int main () {
    
        int counter;
        float rate, annual_amt_used, will, i;
    
        printf("What was the amount of the inheritance?\n");
        scanf("%f", &will);
        printf("\nWhat is the the amount you will use each year?\n");
        scanf("%f", &annual_amt_used);
        printf("\nWhat is the interest rate on the account?\n");
        scanf("%f", &rate);
        printf("\n\nYear\t Payment\t Money Left\n-----------------------------------\n");
    
        counter=1;
        while(will>0)
    
        {
           if(will > annual_amt_used)
           will= will + ((rate/100)*will) - annual_amt_used;
    
        else 
        {
             
           annual_amt_used=will + ((rate/100)*will);
           will=annual_amt_used-annual_amt_used;
        }
    
        printf("%d%15.2f%17.2f\n", counter, annual_amt_used, will);
        counter++;
    
        }
        
    
    system("PAUSE");
    return 0;
    
    }

    Thank You,
    Matt H.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Put // in front of the system("pause"); line of code.

    and add this:

    getchar();

    Now the screen will wait for you press enter, but it will not print a prompt. If that's OK, then you can delete the system line, altogether, and save the file.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    system("PAUSE");
    Remove this!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    244
    Unfortunately, I am using a program called Dev C++ and the program terminates itself before I even get to look at it, unless I include the: system ("PAUSE");


    Thank You for the responses

  5. #5
    Registered User UltraKing227's Avatar
    Join Date
    Jan 2010
    Location
    USA, New york
    Posts
    123
    use getch(). here is an example:

    Code:
    #include <conio.h>
    #include <stdio.h>
    
    int main()
    {
     printf("Im waiting without using a Pause command!\n");
     getch();
    }

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The display of "Press any key to continue", is part of the pause command. You can test it in a console window. Just type pause and hit enter. What do you see displayed?

  7. #7
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    431
    Why do beginners always insist on using dev-cpp? I don't even think it's been updated in the 2nd half of the decade.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  8. #8
    Registered User
    Join Date
    Feb 2010
    Posts
    244
    Our school requires us to. If our program does not compile with Dev C++ they reduce our grade by upto 50%... Im not a big fan of Dev C++ anyways.... lol

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by matthayzon89
    If our program does not compile with Dev C++ they reduce our grade by upto 50%
    Dev-C++ is not a compiler, but an IDE, so you just need to use the MinGW port of gcc 3.4 for the compiler and you should be quite safe.
    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

  10. #10
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    It brings me memories!! Dev C++ has my first c++ compiler and it helped me a lot, but it was almost 'help-free'!
    It was a lot difficult at the beginning also because it provides little debugging info.

    I sure thank god that i use Code::Blocks now!! ( Although i'd prefer it with support for assembly language )

  11. #11
    Registered User
    Join Date
    Jul 2009
    Location
    Croatia
    Posts
    272
    they reduce our grade by upto 50%
    I giggled. Shouldnt school enforce students to try something new and experiment? DevC++ is a joke.

  12. #12
    Registered User UltraKing227's Avatar
    Join Date
    Jan 2010
    Location
    USA, New york
    Posts
    123
    then i gotta replace IDE... since im using DevCpp too.

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Using more than one compiler should be compulsory.

    Not using TurboC at all should be compulsory as well.

    Sadly, neither of these two things is common place.

    At least dev-c++ is only a mildly annoying IDE in front of a good (if a little dated) ANSI compiler.

    Poor TurboC people are still being force-fed something that was rendered obsolete over 20 years ago.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM