-
Then MSVC doesn't have that function...
try rkjd2's suggestion of using windows
I am suprised that you cannot compile that. I have it in Borland. You would think that a Microsoft product would have it...
Code:
# include <windows>
# include <iostream>
using namespace std;
int main()
{
cout << "test";
Sleep (10000); // ten seconds
cout << "complete";
return 0;
}
that will work... sorry to confuse you. I am having a slow brain day...
-
I don't think sleep() type functions are standard.
The name might be something else, you should open up your dos.h, or do some guess and check.
my (djgpp) function is:
delay(x) //Where x is milliseconds
Others might be
sleep()
_sleep()
alarm()
wait()
Also, you might be dealing with milliseconds or seconds, the switching of which could be quite annoying. Either use the semistandard Sleep from windows.h or use your compiler's, which you will need to flush out.
-
OK, finally, that seems to be working. Now, do you think you could help me figure out why my work function if statement is not working correctly? Here is the code:
void CRobot::work()
{
if (task == DRILLING)
sleeping(DRILLTIME);
cout <<robotName<<" has completed the task DRILLING\n";
if (task == LIFTING)
sleeping(LIFTTIME);
cout <<robotName<<" has completed the task LIFTING\n";
if (task == CUTTING)
sleeping(CUTTIME);
cout <<robotName<<" has completed the task CUTTING\n";
if (task == ASSEMBLING)
sleeping(ASSEMBLETIME);
cout <<robotName<<" has completed the task ASSEMBLING\n";
if (task == DISPOSING)
sleeping(DISPOSETIME);
cout <<robotName<<" has completed the task DISPOSING\n";
}
//causes robot to sleep for n seconds
void CRobot::sleeping(int n)
{
int j;
j=1000*n;
Sleep(j);
}
The work function is showing all 5 options instead of just the one that is supposed to be shown. When I call the function, the task should be "CUTTING" but when I compile and run the program, it displays all 5 statements that the robot has completed each task, instead of the one I need it to.
-
An if only binds to whatever immediately follows it, not all the way to the next if. Yoiu will need to put { } around the statement blocks to bind them all to the ifs.
ie
Code:
if (task == DRILLING) {
sleeping(DRILLTIME);
cout <<robotName<<" has completed the task DRILLING\n";
}
-
who would want Sleep to work in seconds? milliseconds are better to work with you can do very short delays easyer. Also, windows.h is pretty common and although big, dosn't take too much longer to load (of corse unless your running off a old 486) btw did u guys hear that mac's are claming that their 800mhz is better than the Processers found in IBM's? am i crazy or are the new 2.2ghz processers about 4 times the speed of the G4's? buying mac is like buying a big car with a small engine and no capacity for upgrade.