Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 23rd, 2008, 4:42 PM   #11
wannabe7
Newbie
 
Join Date: Dec 2007
Posts: 16
Rep Power: 0 wannabe7 is on a distinguished road
Re: My programs aren't running...( no errors)

Quote:
Originally Posted by grumpy View Post
To explain what's happening. The code is "running". However, the program completes and terminates. The system therefore determines that the console window (which was created specifically for the purpose of running the program) to which output has been written is no longer needed, so it destroys the console window. Net effect is that the program disappears before you can see its output.
This is essentially what happens. When I compile and run the program, it quickly terminates after. I don't even get the chance to input the numbers. I am pretty sure (not 100%) that there's no error in it. It was copied exactly from a book by herbert schildt and so I can't seem to figure out what's wrong. I'll try doing some of the suggested things. Other inputs would also help.
wannabe7 is offline   Reply With Quote
Old Feb 23rd, 2008, 5:51 PM   #12
WaltP
Programmer
 
Join Date: Oct 2007
Posts: 39
Rep Power: 0 WaltP is on a distinguished road
Re: My programs aren't running...( no errors)

You don't need other 'inputs'. Stop the program as suggested with cin.get()
__________________
Testing 001 010 011 100....
WaltP is offline   Reply With Quote
Old Feb 23rd, 2008, 6:00 PM   #13
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: My programs aren't running...( no errors)

Quote:
Originally Posted by WaltP View Post
You don't need other 'inputs'. Stop the program as suggested with cin.get()
Rofl...
  1. He meant input, as in advice.
  2. He already has cin statements in his program, that should be stopping the program flow.
It sounds like something's buggy with your compiler since no errors show for anything you write. Are you using Vista? I hear there are severe problems with Vista and Dev-C++.
Sane is offline   Reply With Quote
Old Feb 23rd, 2008, 6:11 PM   #14
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,034
Rep Power: 5 lectricpharaoh will become famous soon enough
Re: My programs aren't running...( no errors)

Quote:
Originally Posted by wannabe7
I am pretty sure (not 100%) that there's no error in it. It was copied exactly from a book by herbert schildt and so I can't seem to figure out what's wrong.
You should know that Schildt's materials have a reputation for inaccuracies and outright errors, such as the use of void main() in examples and what not.

In fact, there is a term for his work: bullschildt.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Feb 24th, 2008, 3:56 PM   #15
wannabe7
Newbie
 
Join Date: Dec 2007
Posts: 16
Rep Power: 0 wannabe7 is on a distinguished road
Re: My programs aren't running...( no errors)

First of all, LOL. "bullschildt," I love it. Well, he's sold over a quarter-million books and he seems to be respected in the community by some people atleast. Also, I did try
 cin.get()
and that didn't work also. Lastly, my operating system is still XP SP2. thanks for the inputs (meaning help ) and I hope someone can find out why this is happening, I'm trying to all the time. Maybe it's the settings?
wannabe7 is offline   Reply With Quote
Old Feb 24th, 2008, 4:27 PM   #16
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Re: My programs aren't running...( no errors)

Methinks that code was given to you under the impression that you had a different problem to what you do have. Have you taken in Sane's advice and corrected it? What errors are you being given by your compiler/IDE?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 24th, 2008, 5:40 PM   #17
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 547
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: My programs aren't running...( no errors)

The proglem is that when you use cin to input an integer the '\n' (Enter key) remains in the keyboard buffer, so you have to remove it or the next cin will fail. I solve this by adding cin.ignore(). after each cin. This is not a foolproof solution -- you can still break the program by typing junk characters after the number you want to enter and before hitting the Return key.

Here is a working program using Dev-C++ compiler.

cplusplus Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int length, width;
  7.  
  8. cout << "Enter the length: ";
  9. cin >> length;
  10. cin.ignore();
  11.  
  12. cout << "Enter the width: ";
  13. cin >> width;
  14. cin.ignore();
  15. cout << "The area is: ";
  16. cout << length * width;
  17. cin.get();
  18. return 0;
  19. }
__________________
True Terror is to wake up one morning and discover that your high school class is running the country - Kurt Vonnegut Jr.
Ancient Dragon is offline   Reply With Quote
Old Feb 24th, 2008, 5:51 PM   #18
WaltP
Programmer
 
Join Date: Oct 2007
Posts: 39
Rep Power: 0 WaltP is on a distinguished road
Re: My programs aren't running...( no errors)

Quote:
Originally Posted by Sane View Post
Quote:
Originally Posted by WaltP View Post
You don't need other 'inputs'. Stop the program as suggested with cin.get()
Rofl...

1) He meant input, as in advice.
I know. He doesn't need more advice because cin.get() is what he needs to do.

Quote:
Originally Posted by Sane View Post
2) He already has cin statements in his program, that should be stopping the program flow.
Yeah, for input. He still needs cin.get() at the end of the program. So far, as far as we can tell, nothing has changed since we have no idea what if anything has been added to his program. Let's stop guessing and wait for him to show us what he's done and what problems still exist, if any.
__________________
Testing 001 010 011 100....
WaltP is offline   Reply With Quote
Old Feb 26th, 2008, 4:10 PM   #19
wannabe7
Newbie
 
Join Date: Dec 2007
Posts: 16
Rep Power: 0 wannabe7 is on a distinguished road
Re: My programs aren't running...( no errors)

Quote:
Originally Posted by Ancient Dragon View Post
The proglem is that when you use cin to input an integer the '\n' (Enter key) remains in the keyboard buffer, so you have to remove it or the next cin will fail. I solve this by adding cin.ignore(). after each cin. This is not a foolproof solution -- you can still break the program by typing junk characters after the number you want to enter and before hitting the Return key.

Here is a working program using Dev-C++ compiler.

cplusplus Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int length, width;
  7.  
  8. cout << "Enter the length: ";
  9. cin >> length;
  10. cin.ignore();
  11.  
  12. cout << "Enter the width: ";
  13. cin >> width;
  14. cin.ignore();
  15. cout << "The area is: ";
  16. cout << length * width;
  17. cin.get();
  18. return 0;
  19. }
Thank you, Ancient Dragon. I will certainly try this. I have used
cin.ignore();
before, but I guess I just forgot about it.
__________________
Aspiring Game Designer
wannabe7 is offline   Reply With Quote
Old Feb 26th, 2008, 9:09 PM   #20
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 547
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: My programs aren't running...( no errors)

Quote:
Originally Posted by Sane View Post
I hear there are severe problems with Vista and Dev-C++.
Not that severe and nothing that can't be easily fixed. The only problem I've had so far is that I had to go into the tools-->compiler options-->directories tab and add the full path to all include and lib paths. I have yet to successfully compile and link a DLL, but its probably something simple too.
__________________
True Terror is to wake up one morning and discover that your high school class is running the country - Kurt Vonnegut Jr.
Ancient Dragon is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Valgrind reports errors with basic programs Jessehk C 4 Feb 24th, 2007 10:07 PM
the best way to pass data between two programs nindoja C# 7 Dec 26th, 2005 11:54 PM
String I/O and Vector Insert errors wingz198 C++ 1 Oct 18th, 2005 9:47 PM
Very annoying errors Aphex_Twin C++ 2 Jun 9th, 2005 3:43 PM
programs running in the background dark_omen C# 0 Mar 6th, 2005 3:46 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:08 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC