Console window closes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • collinsp@sbcglobal.net

    Console window closes

    Can any one help me with the code below. I am just learning C and any
    help would be appreciated. When I run the program the console opens,
    the printf in the function getData prints, I enter the data and when I
    hit return the console closes.
    Thanks
    // Unit 4 Project 44.cpp : Defines the entry point for the console
    application.
    //

    //This program creates customer;s bills for a carpet company

    #include "stdafx.h"

    #define LABOR .35
    #define TAX .085

    // Function Declarations
    void getData (int* l, int* w, float* disc, float* cost);

    int _tmain(int argc, _TCHAR* argv[])
    {
    //Local Declarations
    int l;
    int w;
    float disc;
    float cost;

    //Statements
    getData (&l, &w, &disc, &cost);

    printf("**main: l = %d; w = %d; disc = %f; cost = %f\n", l, w, disc,
    cost);

    return 0;
    } //main

    /* =============== =========getDat a============== ==============
    This function reads two integers and two floats from th ekeyboard.
    Pre All parameters are addresses
    Post Data read into parameter addressess
    */

    void getData (int* l, int* w, float* disc, float* cost)
    {
    printf("Please enter the length, width, discount and cost: ", l, w,
    disc, cost);
    scanf ("%d %d %f %f", l, w, disc, cost);

    printf("**getDa ta: l = %d; w = %d; disc = %f; cost = %f\n", l, w,
    disc, cost);

    return;
    } //getData
  • suresh shenoy

    #2
    Re: Console window closes

    On Feb 24, 4:57 pm, colli...@sbcglo bal.net wrote:
    Can any one help me with the code below. I am just learning C and any
    help would be appreciated. When I run the program the console opens,
    the printf in the function getData prints, I enter the data and when I
    hit return the console closes.
    Thanks
    // Unit 4 Project 44.cpp : Defines the entry point for the console
    application.
    //
    >
    //This program creates customer;s bills for a carpet company
    >
    #include "stdafx.h"
    >
    #define LABOR           .35
    #define TAX                     .085
    >
    // Function Declarations
            void    getData (int* l, int* w, float* disc, float* cost);
    >
    int _tmain(int argc, _TCHAR* argv[])
    {
    //Local Declarations
            int l;
            int w;
            float disc;
            float cost;
    >
    //Statements
            getData (&l, &w, &disc, &cost);
    >
            printf("**main: l = %d; w = %d; disc = %f; cost = %f\n", l, w, disc,
    cost);
    >
            return 0;
    >
    } //main
    >
    /* =============== =========getDat a============== ==============
            This function reads two integers and two floats from th ekeyboard.
                    Pre             All parametersare addresses
                    Post    Data read into parameter addressess
    */
    >
    void getData (int* l, int* w, float* disc, float* cost)
    {
            printf("Please enter the length, width, discount and cost:", l, w,
    disc, cost);
            scanf ("%d %d %f %f", l, w, disc, cost);
    >
            printf("**getDa ta: l = %d; w = %d; disc = %f; cost = %f\n", l, w,
    disc, cost);
    >
            return;
    >
    >
    >
    } //getData- Hide quoted text -
    >
    - Show quoted text -
    I think you dont want the console to close. You could do that by
    putting a getch(); just before the return 0 statement in the main().

    Plz post C questions in C forums.

    Suresh M. Shenoy

    Comment

    • Gopy

      #3
      Re: Console window closes

      On Feb 24, 2:05 pm, suresh shenoy <msureshshe...@ gmail.comwrote:
      On Feb 24, 4:57 pm, colli...@sbcglo bal.net wrote:
      >
      >
      >
      >
      >
      Can any one help me with the code below. I am just learning C and any
      help would be appreciated. When I run the program the console opens,
      the printf in the function getData prints, I enter the data and when I
      hit return the console closes.
      Thanks
      // Unit 4 Project 44.cpp : Defines the entry point for the console
      application.
      //
      >
      //This program creates customer;s bills for a carpet company
      >
      #include "stdafx.h"
      >
      #define LABOR           .35
      #define TAX                     .085
      >
      // Function Declarations
              void    getData (int* l, int* w, float* disc, float*cost);
      >
      int _tmain(int argc, _TCHAR* argv[])
      {
      //Local Declarations
              int l;
              int w;
              float disc;
              float cost;
      >
      //Statements
              getData (&l, &w, &disc, &cost);
      >
              printf("**main: l = %d; w = %d; disc = %f; cost = %f\n", l, w, disc,
      cost);
      >
              return 0;
      >
      } //main
      >
      /* =============== =========getDat a============== ==============
              This function reads two integers and two floats from th ekeyboard.
                      Pre             All parameters are addresses
                      Post    Data read into parameter addressess
      */
      >
      void getData (int* l, int* w, float* disc, float* cost)
      {
              printf("Please enter the length, width, discount and cost: ", l, w,
      disc, cost);
              scanf ("%d %d %f %f", l, w, disc, cost);
      >
              printf("**getDa ta: l = %d; w = %d; disc = %f; cost= %f\n", l, w,
      disc, cost);
      >
              return;
      >
      } //getData- Hide quoted text -
      >
      - Show quoted text -
      >
      I think you dont want the console to close. You could do that by
      putting a getch(); just before the return 0 statement in the main().
      >
      Plz post C questions in C forums.
      >
      Suresh M. Shenoy- Hide quoted text -
      >
      - Show quoted text -

      Comment

      • James Kanze

        #4
        Re: Console window closes

        On Feb 24, 10:57 pm, colli...@sbcglo bal.net wrote:
        Can any one help me with the code below. I am just learning C
        and any help would be appreciated.
        This group discusses C++, not C, and so is unlikely to be of any
        help to you in C. However...
        When I run the program the console opens, the printf in the
        function getData prints, I enter the data and when I hit
        return the console closes.
        That's something outside your program which is doing it. Your
        program never opens a console (and never closes one either). So
        you really should ask in a group specific to your environment.
        // Unit 4 Project 44.cpp : Defines the entry point for the console
        application.
        If your file name ends in .cpp, you're almost certainly working
        in C++, and not C. Your first step is to decide which one you
        want, and use it. Your code looks like C; if that's what you
        want, rename your file to end in .c (and post your questions in
        comp.lang.c).

        Also, your comment above is false for both C and C++. The entry
        point for all applications (console or otherwise) in both C and
        C++ is a function called main, and I don't see any function
        called main in your code.

        --
        James Kanze (GABI Software) email:james.kan ze@gmail.com
        Conseils en informatique orientée objet/
        Beratung in objektorientier ter Datenverarbeitu ng
        9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

        Comment

        • Jim Langston

          #5
          Re: [slightly OT] Console window closes

          collinsp@sbcglo bal.net wrote:
          Can any one help me with the code below. I am just learning C and any
          help would be appreciated. When I run the program the console opens,
          the printf in the function getData prints, I enter the data and when I
          hit return the console closes.
          Thanks
          // Unit 4 Project 44.cpp : Defines the entry point for the console
          application.
          //
          >
          //This program creates customer;s bills for a carpet company
          >
          #include "stdafx.h"
          [SNIP]

          That tells me you are using Microsoft Visual C++ to run the program.

          Hit ctrl-F5 instead of just F5 to run it.


          --
          Jim Langston
          tazmaster@rocke tmail.com


          Comment

          Working...