I want to add a count down timer to my testing software 1hr and 30min
Its a 32bit console application, I want the countdown timer outputted above each question on the right side, timer only needs to output the time left at the top of each question so a live outputted timer is not important, but I would be very grateful if someone could help me use either.
Questions are not random generated.
Also if somebody could help me to output "out of time" if the timer reaches 0
and for the test to end, I think branching is involved not too sure.
I already have, std::srand( std::time(0) ) ; at the start of the test to random
generate the answer order.
Since it doesn't look like you need a high resolution timer, you can probably get away with the facilities provided by the standard C library time. http://www.cplusplus.com/reference/ctime/
#include <iostream>
#include <limits>
#include <ctime> // time_t, difftime, time
int main ()
{
//we just started the program, so let's take a snapshot of the time
std::time_t startTime = std::time(nullptr);
//we'll use this time_t variable to take future snapshots of the time to compare them
//to when we started
std::time_t currentTime;
double seconds;
std::cout << "Input something...";
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::time(¤tTime); //get the time now that the user has entered something and stick it in currentTime
seconds = std::difftime(currentTime, startTime);
std::cout << "It took you " << seconds << " seconds to enter something.\n";
std::cout << "Input something else...";
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::time(¤tTime);
seconds = std::difftime(currentTime, startTime);
std::cout << "It has now been " << seconds << " seconds since you started the program.\n";
return 0;
}
I can't remember ever seeing NULL in a 32bit console application code.
Then you clearly have never read the example code on MSDN. "NULL" is a macro for '0', it is defined in 'WinDef.h' which is a header that gets included into your code throught 'Windows.h'.
@ Computergeek01 I'm not familiar with it probably because I'm not programming too long or enough. In fact I did read that page but because I'm fairly new I'm not sure how to implement this code into my 32 bit console app, and I tried to program with a GUI before (didn't go well) I remember using some nulls to open a message box (can't remember) But I never needed to use them in console app so maybe my comment sounded ignorant which was not meant to be.
Maybe you could explain how to implement this code (SetTimer function) into a 32bit console app ?