www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D program code

reply "Vincent" <spawn_rock2000 yahoo.com> writes:
import std.stdio,std.cstream;

void main(string[] args)
{
	int first;
	int second;
	
	write ("First Number     : ");
	readf (" %s", &first);
	
	write ("Second Number    : ");
	readf (" %s", &second);
	
	int result = first + second;
		
	writeln("Result: ", result);
	din.getc();
}

_________________________________

Problem: When I run this code why it is automatically exit when 
it shows the
          result. It allows me to input first numbers and second 
number but when
          it shows the result it will totally exit and I can't see 
the output.

I use D-IDE as my editor and dmd2 as my compiler.
Nov 13 2013
next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Wednesday, 13 November 2013 at 14:36:22 UTC, Vincent wrote:
          it shows the result it will totally exit and I can't 
 see the output.
din.getc has something in its buffer already (the newline from when you hit enter after readf - it uses the number but left the line), so it doesn't have to wait. Simplest fix is to read two lines at the end: writeln("Result: ", result); readln(); // skip past the enter left from second number readln(); // wait for the user to hit enter again to exit (I'm using readln instead of din so you can just use std.stdio alone)
Nov 13 2013
prev sibling next sibling parent Jacob Carlborg <doob me.com> writes:
On 2013-11-13 15:36, Vincent wrote:

 Problem: When I run this code why it is automatically exit when it shows
 the
           result. It allows me to input first numbers and second number
 but when
           it shows the result it will totally exit and I can't see the
 output.

 I use D-IDE as my editor and dmd2 as my compiler.
You need to tell your IDE to not close the console when the application exists. -- /Jacob Carlborg
Nov 13 2013
prev sibling next sibling parent "Dejan Lekic" <dejan.lekic gmail.com> writes:
 Problem: When I run this code why it is automatically exit when 
 it shows the
          result. It allows me to input first numbers and second 
 number but when
          it shows the result it will totally exit and I can't 
 see the output.

 I use D-IDE as my editor and dmd2 as my compiler.
Add the following line to the end of your main() function: stdin.readln();
Nov 13 2013
prev sibling next sibling parent "Dicebot" <public dicebot.lv> writes:
Changing

readf (" %s", &second);

to

readf (" %s ", &second);

is likely to fix it (untested). There is a "\n" symbol left in 
buffer from last entry (which gets read by `getc`)
Nov 13 2013
prev sibling parent reply "John Colvin" <john.loughran.colvin gmail.com> writes:
On Wednesday, 13 November 2013 at 14:36:22 UTC, Vincent wrote:
 import std.stdio,std.cstream;

 void main(string[] args)
 {
 	int first;
 	int second;
 	
 	write ("First Number     : ");
 	readf (" %s", &first);
 	
 	write ("Second Number    : ");
 	readf (" %s", &second);
 	
 	int result = first + second;
 		
 	writeln("Result: ", result);
 	din.getc();
 }

 _________________________________

 Problem: When I run this code why it is automatically exit when 
 it shows the
          result. It allows me to input first numbers and second 
 number but when
          it shows the result it will totally exit and I can't 
 see the output.

 I use D-IDE as my editor and dmd2 as my compiler.
I see you've got plenty of answers so I'll just add: please ask such questions in digitalmars.D.learn http://forum.dlang.org/group/digitalmars.D.learn
Nov 13 2013
next sibling parent "Vincent" <spawn_rock2000 yahoo.com> writes:
Sorry sir my post is out of place. But thanks anyway next time I 
know now where will I post my topic/questions.

Thanks for the help sirs...
Nov 13 2013
prev sibling parent reply "bachmeier" <no spam.com> writes:
On Wednesday, 13 November 2013 at 14:45:52 UTC, John Colvin wrote:
 On Wednesday, 13 November 2013 at 14:36:22 UTC, Vincent wrote:
 import std.stdio,std.cstream;

 void main(string[] args)
 {
 	int first;
 	int second;
 	
 	write ("First Number     : ");
 	readf (" %s", &first);
 	
 	write ("Second Number    : ");
 	readf (" %s", &second);
 	
 	int result = first + second;
 		
 	writeln("Result: ", result);
 	din.getc();
 }

 _________________________________

 Problem: When I run this code why it is automatically exit 
 when it shows the
         result. It allows me to input first numbers and second 
 number but when
         it shows the result it will totally exit and I can't 
 see the output.

 I use D-IDE as my editor and dmd2 as my compiler.
I see you've got plenty of answers so I'll just add: please ask such questions in digitalmars.D.learn http://forum.dlang.org/group/digitalmars.D.learn
This wouldn't happen so often if digitalmars.D.learn appeared at the top of the page.
Nov 13 2013
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Wednesday, 13 November 2013 at 18:39:59 UTC, bachmeier wrote:
 This wouldn't happen so often if digitalmars.D.learn appeared 
 at the top of the page.
amen, it is so far down that sometimes i forget about it!
Nov 13 2013
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 11/13/13 10:47 AM, Adam D. Ruppe wrote:
 On Wednesday, 13 November 2013 at 18:39:59 UTC, bachmeier wrote:
 This wouldn't happen so often if digitalmars.D.learn appeared at the
 top of the page.
amen, it is so far down that sometimes i forget about it!
bugzillize and pullrequestize! Andrei
Nov 13 2013
parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Wednesday, 13 November 2013 at 20:33:05 UTC, Andrei 
Alexandrescu wrote:
 On 11/13/13 10:47 AM, Adam D. Ruppe wrote:
 On Wednesday, 13 November 2013 at 18:39:59 UTC, bachmeier 
 wrote:
 This wouldn't happen so often if digitalmars.D.learn appeared 
 at the
 top of the page.
amen, it is so far down that sometimes i forget about it!
bugzillize and pullrequestize!
Is it better now?
Nov 13 2013
next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Wednesday, 13 November 2013 at 21:15:32 UTC, Vladimir 
Panteleev wrote:
 Is it better now?
rox!
Nov 13 2013
prev sibling parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 11/13/13 1:15 PM, Vladimir Panteleev wrote:
 On Wednesday, 13 November 2013 at 20:33:05 UTC, Andrei Alexandrescu wrote:
 On 11/13/13 10:47 AM, Adam D. Ruppe wrote:
 On Wednesday, 13 November 2013 at 18:39:59 UTC, bachmeier wrote:
 This wouldn't happen so often if digitalmars.D.learn appeared at the
 top of the page.
amen, it is so far down that sometimes i forget about it!
bugzillize and pullrequestize!
Is it better now?
Yah. That reminds me - the source tree should be in our github... Andrei
Nov 13 2013
parent "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Wednesday, 13 November 2013 at 21:31:51 UTC, Andrei 
Alexandrescu wrote:
 Yah. That reminds me - the source tree should be in our 
 github...
What about the kitchen-sink library it currently depends on? What I'd love to do is get going with http://wiki.dlang.org/Event_system and port DFeed to it, but I have much less free time than I expected...
Nov 13 2013