Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Timer At Input For C++


  • Please log in to reply
No replies to this topic

#1 Glunn11

Glunn11

  • Members
  • 262 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Idaho
  • Local time:06:28 PM

Posted 04 August 2007 - 04:58 PM

Hello again! I am working on a supposedly simple program, where every once in a while a user will be prompted to confirm they are still awake by entering their password. If they do not respond within 30 seconds, the program will end.
Problem is, I can't get timers to cooperate with me: frankly, I don't even understand how they work. I took my timer source code from this website:
http://www.gamedev.net/community/forums/to...=1€

Here is my implemented source code:
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include "timer.h"

using namespace std;

int randomize (int a, int b, int c)
{
	srand(c);
	int value = rand() % (b - a + 1) + a;
	return (value);
}


int main ()
{
	bool timesup = false;
	ofstream yes;
	yes.open("alerts.txt",ios::trunc);
	string playernames[] = {"PATRICK", "DREW", "NICKY", "DES", "ASHLEY", "SHANNON"}, passwords[] = {"SEMISWEET", "CHOCOLATE", "CORNSYRUP", "GENATED-PALM", "MILKFAT", "SKIMMILK"}, password;
	int c = time(NULL);
	int chosen;
	cout << chosen << endl;
	while (timesup != true)
	{
		c++;
		chosen = randomize(0,9000000,c);
		if ((chosen == 0) || (chosen == 1) || (chosen == 2) || (chosen == 3) || (chosen == 4) || (chosen == 5))
		{
			yes << playernames[chosen] << ":\n";
			cout << playernames[chosen] << ", ENTER YOUR PASSWORD: ";
			oops:
			cin >> password;
			Timer timer;
			while(true)
			{
				if(timer.elasped(30000))
				{
					cout << "LOSER!\n";
					timesup = true;
					yes << "LOST!";
				}
				else if (password != passwords[chosen])
				{
					cout << "Incorrect password. Try Again.\n";
					goto oops;
				}
				else if (password == passwords[chosen])
				{
					cout << "Thank you.";
					yes << "CONFIRMED.\n\n";
					break;
				}
			}
		}
	}
}


I am doing my programming on Linux.
Thank you!
P.S: I got my passwords from the back of a Milky Way Midnight Bar ;)
-Glen

Edited by Glunn11, 04 August 2007 - 05:01 PM.


BC AdBot (Login to Remove)

 


m



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users