View previous topic :: View next topic |
Author |
Message |
goldengold Grandmaster Cheater Supreme
Reputation: -1
Joined: 11 Nov 2006 Posts: 1841 Location: -.-
|
Posted: Sat Dec 01, 2007 9:41 am Post subject: Cmd jsyt closes |
|
|
Well im using C# express edition 2008
and when i run my console application after i type the 2nd integer the cmd closes before is shows the answer... (im adding to numbers)
Quote: | Code: |
// Fig. 3.18: Addition.cs
// Displaying the sum of two numbers input from the keyboard.
using System;
public class Addition
{
// Main method begins execution of C# application
public static void Main( string[] args )
{
int number1; // declare first number to add
int number2; // declare second number to add
int sum; // declare sum of number1 and number2
Console.Write( "Enter first integer: " ); // prompt user
// read first number from user
number1 = Convert.ToInt32( Console.ReadLine() );
Console.Write( "Enter second integer: " ); // prompt user
// read second number from user
number2 = Convert.ToInt32( Console.ReadLine() );
sum = number1 + number2; // add numbers
Console.WriteLine( "Sum is {0}", sum ); // display sum
} // end method Main
} // end class Addition
|
|
_________________
|
|
Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Sat Dec 01, 2007 9:43 am Post subject: |
|
|
That's normal.
_________________
|
|
Back to top |
|
 |
goldengold Grandmaster Cheater Supreme
Reputation: -1
Joined: 11 Nov 2006 Posts: 1841 Location: -.-
|
Posted: Sat Dec 01, 2007 9:44 am Post subject: |
|
|
ok... How do i make it NOT close?
_________________
|
|
Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sat Dec 01, 2007 9:47 am Post subject: |
|
|
goldengold wrote: | ok... How do i make it NOT close? |
run it from cmd.
cd <file location>
<file name>
|
|
Back to top |
|
 |
goldengold Grandmaster Cheater Supreme
Reputation: -1
Joined: 11 Nov 2006 Posts: 1841 Location: -.-
|
Posted: Sat Dec 01, 2007 9:52 am Post subject: |
|
|
so thats the only way?
isint there something like
Return (0) or something that doesent close it?
_________________
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Dec 01, 2007 10:10 am Post subject: |
|
|
Code: | Console.Readline(); |
Add the readline after the last input in your code to pause it. (Suggested via a ton of links by searching google. I'm not a C# programmer, but figured I'd say it since no one else has.)
Also, someone wrote their own console class for the reason of not having the ability to use something like getch() as in C/C++ which can be found here:
http://www.codeproject.com/cs/library/csconsolelibrary.asp
You can also import getch as well.
_________________
- Retired. |
|
Back to top |
|
 |
goldengold Grandmaster Cheater Supreme
Reputation: -1
Joined: 11 Nov 2006 Posts: 1841 Location: -.-
|
Posted: Sat Dec 01, 2007 10:12 am Post subject: |
|
|
I found a way to see the answer...
I just step into it
_________________
|
|
Back to top |
|
 |
|