Author Topic: How do I get my code to pause after execution  (Read 9377 times)

Ashley M B

  • Guest
How do I get my code to pause after execution
« on: January 13, 2009, 02:14:06 am »
When I build and run it in Code::Blocks it works fine, and pauses after execution. When it comes to debugging the code using "debugger" it exits the console when the last printf statement should show... What am I doing wrong?  :? The Code I am working with is below:

Code

#include <stdio.h>
#include <stdlib.h>

/******************************
*    Wage Calculator
*       Ashley M Begley
*
******************************/
int s, a;
float b;

int main()
{

    printf("COPYRIGHT INFORMATION\n-------------------\nThis program was designed by Ashley M Begley, who owns all copyright deeds to this program!\n\n");
    printf("\n\n---------------------------------------------\n\nWelcome to 'Wage Pro Estimator'!");
    printf("\n\nThis program is really simple to use. Just answer the questions below and my big brain will work it all out for you ;)");
    printf("\n\n1) What is your hourly pay rate in GBS?: ");
    scanf("%f", &b);


    printf("2) How many shifts have you done this pay period period?: ");
    scanf("%d", &a);

    float wage[a];
    float avg = 0;

    for (s = 0 ; s < a; s++)
    {
        printf("How many hours did you work in shift %d? : ", s+1);
        scanf(" %f", &wage[s]);

        avg += wage[s];
    }
    avg *=b;
    printf("\nYour estimated wage is %.2f GBS", avg);

return 0;
}

« Last Edit: January 13, 2009, 02:16:35 am by Ashley M B »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7699
    • My Best Post
Re: How do I get my code to pause after execution
« Reply #1 on: January 14, 2009, 03:48:37 pm »
This is an beginning programmer question; please ask in a forum open to that type of questions.

I suggest using cprogramming.com.

http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1042856625&id=1043284385

Tim S
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: How do I get my code to pause after execution
« Reply #2 on: January 14, 2009, 04:05:44 pm »
It is not doing anything wrong, the fact it blocks otherwise is a convenience feature of the IDE. You can set that in your project preferences. Normally you do not want a program to block when it is finished, there's no reason for that.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: How do I get my code to pause after execution
« Reply #3 on: January 14, 2009, 04:27:10 pm »
The "pause when execution ends"-configuration does not work if the program is started via debugger.

But in this case the easiest way to keep the console open is to set a breakpoint on the return statement.