Solved

my program won't close

Posted on 2000-04-24
6
156 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

809 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