PDA

View Full Version : C++ question


Bmxpunk86pl
09-19-01, 07:28 PM
Yeah im new to C++ and i have a question. Whenever i write a program, say like a conversion program, i put in my number that will be converted, but before i even see the answer, the program shuts down. Is there anyway to make it stop from shutting down?

engjohn
09-20-01, 12:53 AM
once it gets to the end of the program it will automatically close the window it was running in.

If you put a loop in the program so that you can convert multiple tempuratures then you will not have this prob..

You can also call

system("pause");

if you include the process.h header in your program.

Bmxpunk86pl
09-20-01, 01:58 PM
thanks man!!!!!!!!!1

phungilax
09-20-01, 10:15 PM
you can also execute the program through DOS, and it will not shut down

Bmxpunk86pl
10-29-01, 07:30 PM
engjohn, how would i do that, here is what i did and it doesnt work because it gives me an error in my compiler saying
19 untitled1.cpp
implicit declaration of function `int system(...)'

here is the simple program i made using that

#include <iostream.h>
#include <stdio.h>
#include <process.h>
int main ()
{
int var1;
cout <<"This please put in a number:";
cin>>var1;

int var2;
cout <<"Put in another number:";
cin>>var2;

int answer;
answer = var1 * var2;
cout <<"The answer is:";
cout <<answer;

system("pause");

return 0;
}

Krusty
10-30-01, 01:33 AM
Easiest solution is to put a getchar() or a cin statement at the end. This way, once your program is finished, it sits there and waits for you to enter a key or hit return. That's how I did just about all of my C and C++ programs.

engjohn
11-01-01, 04:06 PM
#include <iostream.h>
#include <process.h>


void pause()
{
system("pause");
}

int main ()
{
int var1, var2, answer;
cout <<"This please put in a number: ";
cin>>var1;

cout <<"Put in another number: ";
cin>>var2;

answer = var1 * var2;
cout <<"The answer is: " << answer <<endl;

pause();

return 0;
}

Bmxpunk86pl
11-01-01, 06:26 PM
oh ok thanks alot

malbolgia
11-01-01, 06:29 PM
also try
getch()

Softwebdev
11-06-01, 11:53 AM
the solution in c++ is endless............you will have fun if you play with it every day

ButcherUK
11-08-01, 09:44 AM
Originally posted by Bmxpunk86pl
engjohn, how would i do that, here is what i did and it doesnt work because it gives me an error in my compiler saying
19 untitled1.cpp
implicit declaration of function `int system(...)'


that's because system() is in stdlib.h not process.h

Softwebdev
11-08-01, 01:03 PM
why learn c++? when you can learn c#

this thing is new ....soon or later c++ will be like c....

engjohn
11-08-01, 03:50 PM
Originally posted by ButcherUK


that's because system() is in stdlib.h not process.h

I just checked and it IS in process.h AND stdlib.h on my system,
I am using Visual Studio Enterprise Edition. <-- Probably a MS thing...

It is in stdlib.h on my linux system.

engjohn
11-08-01, 03:53 PM
Originally posted by Softwebdev
why learn c++? when you can learn c#

this thing is new ....soon or later c++ will be like c....

From what I have read c# has the ease of VB and SOME/most of the
power of c/c++. It does NOT have all of the power of c/c++.

ButcherUK
11-09-01, 02:04 PM
C# is more of a java replacement than a C++ replacement. It' just because Sun stopped them making J++ how they wanted, so they turned the old J++ into C#

Softwebdev
11-09-01, 02:38 PM
Originally posted by ButcherUK
C# is more of a java replacement than a C++ replacement. It' just because Sun stopped them making J++ how they wanted, so they turned the old J++ into C#

can't agree more...........do you think that c# will win over java ?

i doubt it

ButcherUK
11-09-01, 07:11 PM
I think both will gain their own group of followers, people have said all sorts of languages will be replaced, but they haven't even oldies such as COBOL, Pascal and Fortran are still around :)