Shutting Down Programs

This is a discussion on Shutting Down Programs within the C++ Programming forums, part of the General Programming Boards category; Hi, I started another thread but I think people misunderstood what I was asking and then it just turned into ...

  1. #1
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128

    Shutting Down Programs

    Hi, I started another thread but I think people misunderstood what I was asking and then it just turned into an argument that had little to do with my original question, quite amusing but not that helpful.

    What I want to do is run the program and when the user signals the end of the program I want to display Thank You bye for a second or so then the program shuts down (exits itself) I have everything else down except the shutting down process, Please could someone Help me.

    Here is the code:

    Code:
    /*Program to work out the price of any quantity
    of products at any price, plus any rate of vat*/
    #include <iostream.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <string.h>
    
    
    int main(void)
    
    {
    
    	//Declare the variables
    	float cost, quant, price, vat, full, temp;
    	int length, count;
    	char yesno, vats[10];
    
    		  while (yesno != 'n' && yesno != 'N')
    		  {
    				//Get info from user
    				clrscr();
    
    				cout<<"Please enter the price of the product: ";
    				cin>>cost;
    				cout<<"\n\n";
    				cout<<"Please enter the quantity of products: ";
    				cin>>quant;
    				cout<<"\n\n";
    				cout<<"Please enter your rate of vat: ";
    				cin.ignore();
    				cin.getline(vats, 10);
    
    				length=strlen(vats);
    
    				if (length == 0)
    				{
    					 temp = 17.5;
    				}
    
    				else
    				{
    					 temp=atof(vats);
    				}
    
    
    				cout<<"\n\n\n";
    
    				//do the calculation
    				temp= temp / 100;
    				price= cost * quant;
    				vat= cost * quant * temp;
    				full= price + vat;
    
    
    				//give the answer
    				cout<<"The price of "<<quant<<" product(s) at "<<cost<<" each = "<<price<<"\n\n"
    				"The vat = "<<vat<<"\n\n"
    				"Price plus vat = "<<full<<"\n\n";
    
    				cout<<"Would you like to use the program again? ";
    				cin>>yesno;
    				cout<<"\n";
    
    		  }
    		  clrscr();
    		  cout<<"\n\n\n\n\n\n\n\n\n\nThankyou Bye!";
    
    		  for (int i=0; i<=5000; i++)
    		  {
    				for (int j=0; j<=2500; j++)
    				{
    				}
    		  }
    		  
    
    return 0;
    }
    The for loops don't have code missing, I am a newbie so that is the only way I could think to get a delay before quitting the program.

    Thanks.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    - Include windows.h
    - Remove your for loops
    - Add: Sleep(2000); for a 2 second delay.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    Thanks for that but I am using Borland 4.52, I probably should have said before and the sleep and delay function don't seem to work with this compiler.

  4. #4
    Registered User Mario's Avatar
    Join Date
    May 2002
    Posts
    317
    Well, it seems you were the one not understanding the answers you received.
    You say you have the waiting period already sorted out. Fine, although I would argue against your method. So now you just want a way to exit the program... you code already does that! I don't see what's the problem.

    As for the answers you received on that other thread. We gave you 2 ways to exit the application. Through 'exit(0)' and through 'return 0'. I think it was quite helpful considering what you asked was how to exit an application.
    Regards,
    Mario Figueiredo
    Using Borland C++ Builder 5

    Read the Tao of Programming
    This advise was brought to you by the Comitee for a Service Packless World

  5. #5
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    That maybe the case Mario, I probably didn't understand the answers given, as I said I am new to all this so if people come along saying things I don't understand does that make me a fool, I think not, The thing is My compiler doesn't close the program with return 0; or exit(0); so I was asking for someone to elaborate, if I dodn't understand this elaboration I'm sorry and I appologise for offending you with my ignorance, I don't think I am going to come here for help anymore as it just seems to be a place where people want to show how good they are at the expense of others, this isn't a very encouraging environment for people new to programming to come into, I try to be nice and ask questions in a polite manner and then get slated for not understanding the answers.

    I have been doing C++ for under 3 months I have written only simple programs alot of the stuff on these boards I don't understand, that doesn't bother me as I know I'm only starting but getting harshly worded replies isn't nice at all.

    Thanks alot.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  6. #6
    Registered User Mario's Avatar
    Join Date
    May 2002
    Posts
    317
    Oohh... c'mon UnclePunker! No one here got any offense. It's just a simple thread.

    > as I said I am new to all this so if people come along saying things I don't understand does that make me a fool, I think not

    Off course not! I was just giving you another perspective at what you called entertaining but not useful. To help you realize that was in fact the answer you were looking for.

    >The thing is My compiler doesn't close the program with return 0; or exit(0); so I was asking for someone to elaborate

    You see? How could we know that up untill now? It's not something one could guess. So, according to our knowledge of your problem, we gave the best answer possible.

    But let me tell you that sounds fishy. Maybe something to do with how your console is configured. I'm sure the program exits. It's just the console that doesn't close. Take a look at the title bar of your console when you run the application and signal it to end. If it reads closed or something like that, click on the properties button below the title bar and set it to close on exit... I don't remember the details as I have Windows ME on this machine (urgh!), but just fiddle with the options there. It should read something like that.

    >I don't think I am going to come here for help anymore as it just seems to be a place where people want to show how good they are at the expense of others

    Hehe... I'm sure you are not talking about me. I'm your next door newbie. Trust me.
    But still, that is entirely untrue. I'm sure you know that. But even if it was, personally I don't give a damn if someone tries to take advantage of my inexperience. While they do that, I'm learning with their answers.
    Regards,
    Mario Figueiredo
    Using Borland C++ Builder 5

    Read the Tao of Programming
    This advise was brought to you by the Comitee for a Service Packless World

  7. #7
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    O.k maybe I had a bit of a rant, and it's a fair point that I didn't give the details of my compiler, I have added it as a signature now.

    Well, it seems you were the one not understanding the answers you received.
    That to me sounds like your pulling me down, but if you say you were'nt o.k.

    I explained in the abpve reply that is how I figured to get a delay, if you know any beter way I am always open to ideas, if I don't understand these then I don't think it's unfair to say so.

    It seems plausible to me that you are right and my console probably isn't configured correctly, I have been using return 0; for ages, I wouldn't get very far without exiting applications but it just says inactive in the top of the window, maybe this means it should've closed I don't know I'll have a look at the options.

    You have to admit that the thread went off the subject a bit, it turned into an argument about who was right and who was wrong, that sort of things may put some people who aren't as confident with programming off as they may think if they post their code they will get slated, that is just my opinion, hopefully it hasn't offended anyone.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  8. #8
    Registered User GreenCherry's Avatar
    Join Date
    Mar 2002
    Posts
    65
    The reason you shouldn't include the for statements is because the computer can do them in less than a second.

  9. #9
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    I think that many problems would be solved if you updated your compiler...or downloaded say bloodshed devc++ so that you can use the windows.h method that hammer described...i believe that that is probably the only viable way to pause the program (without user intervention but that defeats the purpose). It may be possible to use the for loop....but you would have to count to a couple billion trillion to even phase the processor....pentium 4's do a couple trillion calcualations per second...so it really comes down to your target users. good luck.
    PHP and XML
    Let's talk about SAX

  10. #10
    Unregistered
    Guest
    Thanks, I will consider upgrading soon, the for loops do create a short delay I promise, I am using a measley gig AMD athlon processor but I promise it does create a short delay, the delay thing is just to show the polite ending message so it doesn't need to long, does anybody have advice on how to change the console options to shut down instead of staying open and saying inactive, or do I have to update my compiler for that?

    Please don't get me for being stupid.

  11. #11
    Registered User Mario's Avatar
    Join Date
    May 2002
    Posts
    317
    What's your OS?
    Regards,
    Mario Figueiredo
    Using Borland C++ Builder 5

    Read the Tao of Programming
    This advise was brought to you by the Comitee for a Service Packless World

  12. #12
    Unregistered
    Guest
    Windows 98, I only know a bit about computers, I'm about to start studying them, I apologise if I am being stupid.

  13. #13
    Registered User Mario's Avatar
    Join Date
    May 2002
    Posts
    317
    Dang! I was afraid you would say that. I don't remember how to do it in windows 9x...

    hmm... didn't you find a 'close on exit' checkbox when you click on the properties button?
    Regards,
    Mario Figueiredo
    Using Borland C++ Builder 5

    Read the Tao of Programming
    This advise was brought to you by the Comitee for a Service Packless World

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Starting programs
    By Molokai in forum C Programming
    Replies: 1
    Last Post: 04-16-2009, 10:10 AM
  2. Recommend upgrade path for C programs
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-22-2007, 06:32 AM
  3. I never Finish my programs :(
    By epidemic in forum C++ Programming
    Replies: 11
    Last Post: 04-02-2007, 12:35 PM
  4. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 04:42 AM
  5. executing c++ programs on the web
    By gulti01 in forum C++ Programming
    Replies: 4
    Last Post: 08-12-2002, 03:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21