Solved

my program won't close

Posted on 2000-04-24
6
153 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 learn how to clear a vector as well as how to detect empty vectors in C++.

707 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

15 Experts available now in Live!

Get 1:1 Help Now