C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 7th, 2008, 04:15 PM
#include <Hspd> #include <Hspd> is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 30 #include <Hspd> User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 48 m 4 sec
Reputation Power: 11
C++ Multitasking

Can anyone tell me where I might look to start somewhat researching on how to enable usage of dual core machines or multitasking?

Also I'm having a problem with an assignment of mine, I've asked for help from other programmers, but either I can't quite understand the code they provide or they don't know ???

The thing is I'm supposed to create an elevator simulator. A person starts on the bottom floor of a 2 story building at the beginning of the day and of course travels to the 2nd floor. The elevator takes 5 seconds to climb each floor and beeps once every second (annoying I know) anyways... along with timing that out... every 20 seconds the simulator is supposed to schedule a random arrival on either the first or second floor. I'm having a problem timing out the 20 seconds while still keeping track of the 5 second climbs with 1 second beeps. Any help would be appreciated.

as for the beep every 1 second for 5 seconds I got that covered somewhat, however I'm not sure if I'd have to change it to fit in the 20 second timer or not.

Code:
#include <iostream>
#include <ctime>
using namespace std;

int main()
{
    void timer();
    
    timer();

    
system("PAUSE");
return 0;
}

void timer()
{
    int oldtime = time(NULL);
    int tick = oldtime;
    
    
    
        while(time(NULL) < oldtime+6)
        {    
             if(tick < time(NULL))
             {       tick = time(NULL);
                     cout <<"\a"<<endl;
             }
             
        }
}

Reply With Quote
  #2  
Old January 9th, 2008, 08:07 AM
#include <Hspd> #include <Hspd> is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 30 #include <Hspd> User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 48 m 4 sec
Reputation Power: 11
Omg

OMG guys thanks for all your help...

I mean without all your help I would have just had to figure it out all by my lonesome with a bit of help from a friend of mine I'm so glad I could count on you guys

here's my ending code in case you all had a problem with it.

And yes I realize I didn't put it all into classes, I was too busy trying to figure out how to make it work so for now, functions will do.

Code:
#include <iostream>
#include <ctime>
using namespace std;

int originalTime;

int main()
{



	void scheduler();
	void liftTimer();
	
again:
	liftTimer();
	scheduler();
	goto again;
	

}

void liftTimer()
{
	int tick;

	originalTime = (unsigned int)time(NULL);
	tick = originalTime;

	while(time(NULL) <= originalTime + 5)
	{
		if(tick < time(NULL))
		{
			
			tick = (unsigned int)time(NULL);
			cout << "\a" << endl;
		}
	}
}

void scheduler()
{
	while(time(NULL) != originalTime + 20)
	{
		//does nothing, only checks the condition repeatedly.
	}
	
	originalTime = (unsigned int)time(NULL);

	cout <<"There is a new arrival on floor 1 or 2" << endl; //which floor it is will be handled by another function
															 //or whatever.
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > C++ Multitasking


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap