Solved

my program won't close

Posted on 2000-04-24
6
160 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 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
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 viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

726 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