Solved

my program won't close

Posted on 2000-04-24
6
154 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
  • 4
  • 2
6 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 60 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now