Console window closes

C

collinsp

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

/* ========================getData============================
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("**getData: l = %d; w = %d; disc = %f; cost = %f\n", l, w,
disc, cost);

return;
} //getData
 
S

suresh shenoy

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

/* ========================getData============================
        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("**getData: 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
 
G

Gopy

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;
/* ========================getData============================
        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("**getData: 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 -
 
J

James Kanze

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.
 
J

Jim Langston

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top