0

I hope this doesnt constitute as me asking for answers but I am running a program and at the end I am asked for the program to wait 10 seconds after saying goodbye and prompted back to main menu. I have researched this on google and from some of the results I have found they are not clear. Could one of you guys show me how to make this timer work for 10 seconds...

//Class: C++ 230
//Date: 2/16/10
//Assignment: final
//This program is my final for C++ 230
//This program will perform typical functions of a normal ATM machine
#include <iostream>
#include <iomanip>
using namespace std;

//Function prototypes
void showMenu();
int mainMenuSelection(int);
void welcomeScreen();
double enterAmountScreen(double);
int anotherTransactionScreen(int);
void goodbyeScreen();
void wait(long);

//int main function
int main ()
{
	//Declare variables
	int choice;
	
	//Set the numeric output formatting
	cout << fixed << showpoint << setprecision(2);

	//Function for welcome screen
	welcomeScreen();
	
	//Create a do\while loop
	do
	{
		//Display the menu and get the user's choice.
		showMenu();
		cin >> choice;

		//Validate the menu selection.
		while (choice < 1 || choice > 5)
		{
			cout << "Please enter 1, 2, 3, 4, or 5: ";
			cin >> choice;
		}
		
		//Function to choose in the main menu selection
		mainMenuSelection(choice);

	} while (choice != 5);
	
	return 0;
}
	
//Function to show the main menu
void showMenu()
	{
		//Display the main menu screen
		cout << endl << "\t\tMain Menu Screen" << endl << endl;
		cout << "1) Withdrawal" << endl;
		cout << "2) Deposit" << endl;
		cout << "3) Check Balance" << endl;
		cout << "4) Funds Transfer" << endl;
		cout << "5) Exit ATM" << endl << endl;
		cout << "Enter your choice: ";
	}
	
//Function to choose in the main menu screen
int mainMenuSelection(int choice)
	{
		//Declare variables in mainMenuSelection
		int withdrawChoice,
		    depositChoice,
		    checkBalanceChoice,
		    fundsTransferChoice;
		double money = 0.0;

		//Respond to user's menu selection
		switch (choice)
		{
		case 1:
			//Perform do\while loop to check for correct validation
			do
			{
				//Show output of function
				cout <<"\t\tWithdrawal Screen" << endl << endl;
				cout << "1) From Checking" << endl;
				cout << "2) From Savings" << endl;
				cout << "3) Quick Cash" << endl;
				cout << "4) Back to Main Menu" << endl;
				cout << "Enter your withdraw choice: ";
				cin >> withdrawChoice;

				while (withdrawChoice < 1 || withdrawChoice > 4)
				{
					cout << "Please reenter 1, 2, 3, 4: ";
					cin >> withdrawChoice;
				}

				if (withdrawChoice != 4)
				{
					int val = enterAmountScreen(money);
					return -1;
				}
					
			} while (withdrawChoice != 4);
			
			//Back to main menu option
			if (withdrawChoice == 4)
			{
				return -1;
			}
			break;

		case 2:
			//Perform do\while loop to check for correct validation
			do
			{
				cout <<"\t\tDeposit Screen" << endl << endl;
				cout << "1) To Checking" << endl;
				cout << "2) To Savings" << endl;
				cout << "3) Back to Main Menu" << endl;
				cout << "Enter your deposit choice: ";
				cin >> depositChoice;

				while (depositChoice < 1 || depositChoice > 3)
				{
					cout << "Please reenter 1, 2, or 3: ";
					cin >> depositChoice;
				}

				if (depositChoice !=3)
				{
					int val = enterAmountScreen(money);
					return -1;
				}

			} while (depositChoice != 3);

			//Back to main menu option
			if (depositChoice == 3)
			{
				return -1;
			}
			break;

		case 3:
			//Perform do\while loop to check for correct validation
			do
			{
				cout << "\t\tCheck Balance Screen" << endl << endl;
				cout << "1) From Checking" << endl;
				cout << "2) From Savings" << endl;
				cout << "3) Back to Main Menu" << endl;
				cout << "Enter Your Check Balance Choice: ";
				cin >> checkBalanceChoice;

				while (checkBalanceChoice < 1 || checkBalanceChoice > 3)
				{
					cout << "Please reenter 1, 2, or 3: ";
					cin >> checkBalanceChoice;
				}

			} while (checkBalanceChoice != 3);

			//Back to main menu option
			if (checkBalanceChoice ==3)
			{
				return -1;
			}
			break;

		case 4:
			//Perform do\while loop to check for correct validation
			do
			{
				cout << "\t\tFunds Transfer Screen" << endl << endl;
				cout << "1) From Savings to Checking" << endl;
				cout << "2) From Checking to Savings" << endl;
				cout << "3) Back to Main Menu" << endl;
				cout << "Enter Your Funds Transfer Choice: ";
				cin >> fundsTransferChoice;

				while (fundsTransferChoice < 1 || fundsTransferChoice > 3)
				{
					cout << "Please reenter 1, 2, or 3: ";
					cin >> fundsTransferChoice;
				}
				
				if (fundsTransferChoice != 3)
				{
					int val = enterAmountScreen(money);
					return -1;
				}

			} while (fundsTransferChoice != 3);

			//Back to main menu option
			if (choice == 3)
			{
				return -1;
			}
			break;

		case 5:
			//End the program if 5 is selected
			cout << "Program ending." << endl << endl;
			break;
		}
		return 0;
	}
	
//Function to display the welcome screen
void welcomeScreen()
		{
			//Show output of function
			cout << "Hit enter to simulate inserting card";
			//Hit enter to go to the next screen
			cin.get();
		}

//Function to enter amount screen
double enterAmountScreen(double money)
{
	//Declare function variables
	int decision,
	anotherTransactionChoice = 0;
			
	//Show output of function
	cout << endl << "\t\tEnter Amount Screen" << endl;
	cout << "1) Enter an amount:";
	cout << endl << "2) Back to Main Menu:";
	cout << endl << "Enter your decision for the amount screen: ";
	cin >> decision;
			
	//Return to main menu option
	if (decision == 2)
	{
		return -1;
	}
	else
	{
		cout << "Please enter the amount: ";
		cin >> money;
		anotherTransactionScreen(anotherTransactionChoice);
	}

	return money;
}

//Function to enter another transaction screen
int anotherTransactionScreen(int anotherTransactionChoice)
{
	do
	{
		cout << endl << "\t\tAnother Transaction Screen" << endl;
		cout << "1.) Enter another transaction" << endl;
		cout << "2.) Exit the ATM ";
		cout << endl << "Please make a selection ";
		cin >> anotherTransactionChoice;

		while (anotherTransactionChoice < 1 || anotherTransactionChoice > 2)
		{
			cout << "Please reenter 1 or 2: ";
			cin >> anotherTransactionChoice;
		}

		if (anotherTransactionChoice == 1)
		{
			return -1;
		}

		if (anotherTransactionChoice == 2)
		{
			goodbyeScreen();
			return 1;
		}

	} while (anotherTransactionChoice == 2 || anotherTransactionChoice == 1);

	return anotherTransactionChoice;
}

//Function to display goodbye Screen
void goodbyeScreen()
{
	//Declare variables in goodbye screen
	long seconds = 10;

	//Display a goodbye message
	cout << endl << endl << "Have a nice day!" << endl << endl;
	wait(seconds);
}

//Function to wait 10 seconds before returning to main menu
void wait(long seconds)
{
	seconds = seconds * 1000;
}
4
Contributors
8
Replies
13
Views
7 Years
Discussion Span
Last Post by necrolin
0

What function are you calling to actually perform the wait? All I see is math done on the value to wait.

0

Here are the instructions

Goodbye Screen (screen 7)
display goodbye message, wait 10 seconds, cycle back to welcome screen

0

Here are the instructions

Goodbye Screen (screen 7)
display goodbye message, wait 10 seconds, cycle back to welcome screen

Very good. I repeat:

What function are you calling to actually perform the wait?

2

if u wanna be a dick dont respond to my questions

Actually what WaltP stated was correct. You're not calling any function that makes the computer wait 10 seconds. Instead of calling him names a more constructive approach would be to state that you realize that you're not calling a function to make the computer wait because you have no idea how to implement such a function yet and that's fine. No problems. But do try to be polite.

There's more than one way to implement a wait period. Here's one solution for you:

http://www.daniweb.com/forums/thread65024.html

0

i apologize for that but I just thought this was kind of rude...

Very good. I repeat:




Originally Posted by WaltP View Post

What function are you calling to actually perform the wait?

-2

This is a final?
I'd go install allegro and create a reall sweet gui for this. Clicking buttons and all. But in anycase I can't help.

Votes + Comments
Why are you posting worthless comments in a request for help?
0

i apologize for that but I just thought this was kind of rude...

Very good. I repeat:




Originally Posted by WaltP View Post

What function are you calling to actually perform the wait?

The sleep() function was used in the post that I linked to. It uses milliseconds as a base wait period. So you can do Sleep(1000); for example.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.