Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

my program won't close

Posted on 2000-04-24
6
Medium Priority
?
162 Views
Last Modified: 2010-04-02
I have this

//Closes program in 5 seconds
cout << "Closing in 5 seconds";
cout.flush();
Sleep( 5000 );

what do I put after that to get it to close?

Also is there a way I could get it to count down? like 5 - 4 - 3 - 2 - 1 close.
0
Comment
Question by:nationnon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 240 total points
ID: 2743464
After the Sleep() you should just retirn from main().  Like

int main()
{
   cout << "Closing in 5 seconds";
   cout.flush();
   Sleep( 5000 );
   return 0;
}

continues.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2743469
To make it count down you could do something like

int main()
{
   cout << "Closing in 5 seconds";
   cout.flush();

   for (int i=5; i > 0; --i)
   {
      cout << i << endl;
      Sleep( 1000 );
   }
   return 0;
}
0
 
LVL 22

Expert Comment

by:nietod
ID: 2743472
Now the numbers printed by this 5,4,3... will appear on seperate lines,  That is the new number doesn't replace the old number.   In standard C++ that is the best you can do.  Standard C++ provides no mechansism for you to move the cursor or to change information that was previously displayed However, since this is for windows, windows does provide some windows-specific functions that would allow you to move the cursor so the new number overwrites the old one.  (use of these function would mean the code could not be compiled for non-windows computers.)  I don't know if that matters at all for you.

Let me know if you have any questions.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:nationnon
ID: 2743511
Adjusted points from 50 to 60
0
 
LVL 1

Author Comment

by:nationnon
ID: 2743512
I got two errors.
can you explain them for me?

---------------------------------------

#include <iostream.h>
#include <windows.h>

double deduction()
{

//variable definitions

const double sTaxPct = .08;
const double fTaxPct = .32;
const double miscPct = .20;
return (sTaxPct + fTaxPct + miscPct);

}//end calculation function



void main()

// Declare and define variables
{

char EfirstName[50] [10];
char ElastName[50] [10];
//char sEfirstName[10];
//char sElastName[10];
double EgPay[50];
double EnPay[50];
//double sEgPay;
//double sEnPay;
double Erate[50];
double Ehrs[50];
//double sErate;
//double sEhrs;
int nEmployee;

//char c();





//User entered information

cout <<"Enter first employee's last name: ";
cin >> ElastName[0];
cout <<"Enter first employee's first name: ";
cin >> EfirstName[0];
cout <<"Enter first employee's pay rate: ";
cin >> Erate[0];
cout <<"Enter first employee's hours: ";
cin >> Ehrs[0];
cout << "Enter second employee's last name: ";
cin >> ElastName[1];
cout << "Enter second employee's first name: ";
cin >> EfirstName[1];
cout << "Enter second employee's hours: ";
cin >> Ehrs[1];
cout << "Enter second employee's rate: ";
cin >> Erate[1];

// employee hours * rate & netpay deduction
EgPay[0] = Erate[0] * Ehrs[0];
EgPay[1] = Erate[1] * Ehrs[1];
//sEgPay[0] = fErate * sEhrs;
EnPay[0] = EgPay[0] * deduction();
EnPay[1] = EgPay[1] * deduction();
//sEnPay = sEgPay * deduction();

// ask user which employee they want to view

cout << "Choose Employee 1 or 2: ";
cin >> nEmployee;

// If statement with output for program

if (nEmployee<=1)
cout << EfirstName[0] << " " << ElastName[0] << "'s gross pay was " << EgPay[0] << " "<< "but after deductions the pay is now " << EnPay[0] << endl;
    cout <<  endl;
if (nEmployee>=2)
      cout << EfirstName[1] << " " << ElastName[1] << "'s gross pay was " << EgPay[1] << " " << "but after deductions the pay is now " << EnPay[1] << endl;
      cout << endl;

//Closes program in 5 seconds

}
  int main()
{
   cout << "Closing in 5 seconds";
   cout.flush();

   for (int i=5; i > 0; --i)
   {
      cout << i << endl;
      Sleep( 1000 );
   }
   return 0;
}

-----------------------------------
1. error C2556: 'int __cdecl main(void)' : overloaded function differs only by return type from 'void __cdecl main(void)'
2. 'main' : redefinition; different basic types

0
 
LVL 22

Expert Comment

by:nietod
ID: 2743689
You have two "main()" functions declared there.  You can only have one main function.  

You need to put the code i wrote (which I wrote in a simple main function) into your main function.

also main should be declared to return "int" not "void".
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question