how do I make one? I have one at school but i forget how and i am at home right now...
Printable View
how do I make one? I have one at school but i forget how and i am at home right now...
BTW, this is Wraith_Master, but kinda in a lazy mood right now :)
Delay the program by a second? Use Sleep(1000), in windows.h
Code:#include <time.h>
void Wait ( int Seconds );
void Wait ( int Seconds )
{
clock_t endtime = clock() + Seconds * CLOCKS_PER_SEC;
while ( ( clock() < endtime ) );
}
There's a hack for ya.Code:void sleep(time_t seconds)
{
time_t now = time(NULL);
while ((seconds + now) < time(NULL)) {};
}
thanks...
I am a newbie programmer and dont understand this code:
void sleep(time_t seconds)
{
time_t now = time(NULL);
while ((seconds + now) < time(NULL)) {};
}
where do i put the number of seconds i want it to wait for. If I chose 10 secs will it look like this?:
void sleep(time_t 10)
{
time_t now = time(NULL);
while ((10 + now) < time(NULL)) {};
}
and what do i put in for now? im lost.
Leave the sleep function alone.
When you call sleep, do it like so.
printf("Hello\n");
sleep(3);
That's all
Please don't grave dig.
Moerators?
i dont get this here is my code:
I got both the clear screen code and sleep code from this site and the clear screen thing works but not the sleep.Code:#include "stdafx.h"
#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include <iostream.h>
#include <time.h>
#include <stdlib.h>
char playername[9];
int caller;
int clrscr(void);
int getch(void);
void sleep(time_t seconds);
int main(void)
{
cout << "Still in the making Copyright 2003 All rights reserved.";
printf("Press a key to continue...");
getch();
caller = clrscr();
cout << "Enter your name (8 max characters): ";
cin >> playername;
cout << "Welcome " << playername << endl;
sleep(100000);
return 0;
}
int clrscr(void)
{
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
return idisplay;
}
void sleep(time_t seconds)
{
time_t now = time(NULL);
while ((seconds + now) < time(NULL)) {};
}
Can anyone tell me whats wrong
Ok, remove your function for sleep.
Remove the prototype for sleep and all of the sleep calls.
Since you're using windows.h simply call Sleep(number here) except make sure the S is uppercase.
If that won't give you a go, use the delay function I submitted. Sleep restricts you to Windows.
thank you so much that helped alot and it works now. So much easier than all that other stuff :) :p :cool:
thanks a bunch
I'm glad to hear it.
By the way, since you're new, lets start you off on the right foot. When posting code, use code tags.
One more question. I want a user to input a number from 1 to 5 so i put the code cin >> inum;
but if they input an interger that is not a num from 1 to 5 or a char it wouldnt work like i wanted it to also it would keep going throughout the program. In basic i would just do:
How can i do the same in c++?Code:lbl question
input blah blah
if blah = 1-5
then
dothis stuff
else
goto question
endif
If it was C, I could tell you. I'm not all that great in C++. I'm rusty as heck.
Anybody want to give this person some help?
I'd say research C++ if statements. :)
lbl question
input blah blah
if blah = 1-5
then
dothis stuff
else
goto question
endif
Code:do
{
int input;
cout << "Enter number between 1 and 5: ";
while (cin >> input)
cout << "\nError! Must enter an integer: "
} while (input > 0 && input < 6);
dothisstuff();