C/C++ :: Timer Will Start From Its Previous Value Instead Of Its Initial Value?
May 8, 2014
I am making a product and in which i use a timer. I want when the product is being start the timer will run and when the product is off the timer will stop. If i again start the product the timer will start from its previous value.
I have problem that the timer start from its initial when i start my product.
I have a semi-working program for doing this task. Here it is:
char c = 0, flag = 0, c_ = 0; while ((c = getchar()) != '.') { if ((c >= '0'&& c <= '9') && (c_ <'0' || c_ >'9')) { if (c == '0') flag = 1; } else putchar(c);
[code].....
But when I enter "000000a123000500" the program returns "0a23000500" instead of "0a123000500". Please change my program to have it do what it need to or give me some hint. Using getchar and putchar only! No massives and pointers!
I've been trying to store the inital size of a list in an int variable, so I can access it later in case I modify the list size. For example, I did the following:
std::list<AType *> myList; myList.push_back(anATypeobject); int initListSize = myList.size(); //initial list size myList.push_back(anotherATypeobject); myList.push_back(yetanotherATypeobject); while(myList.size > initListSize) myList.pop_back();
What this is supposed to do is to get an initial size of a list, and then be able to return to that initial size. However, when I try to do it in my code, initListSize always change if myList.size() changes. Is there a way to change that?
I am having some trouble creating a listbox in visual studio. I declared an array, set initial values, and now I would like to be able to update those values. It is a pizza inventory app, so I need to update the initial values once the user has added inventory. This is the code I have for the "Update Inventory" button:
// read in value and convert to double double dblInput = Convert.ToDouble(txtInput.Text); // loop through ingredients and add inventory to selected ingredient for (int i = 0; i < dblInventory.Length; i++) { // is item at i checked for update? if(lstInventory.GetItemCheckState(i) == CheckState.Checked)
There was an "impovement" since Windows 7 in algorithm for selecting the initial directory, which is described here OPENFILENAME structure. Briefly:
Windows 7:
If lpstrInitialDir has the same value as was passed the first time the application used an Open or Save As dialog box, the path most recently selected by the user is used as the initial directory. Otherwise, if lpstrFile contains a path, that path is the initial directory.
Otherwise, if lpstrInitialDir is not NULL, it specifies the initial directory. If lpstrInitialDir is NULL and the current directory contains any files of the specified filter types, the initial directory is the current directory. Otherwise, the initial directory is the personal files directory of the current user. Otherwise, the initial directory is the Desktop folder.
The problem that this behavior is not what users of my program expect. Another constraint is that I need to use old CFileDialog dialog, not Common File Dialogs. I've tried to use advises described on StackOverflow and on MSDN. This solution by EllisMiller works perfectly:
Specifying a full path (including filename) in lpstrFile. The filename of course shows up in the filename box which is annoying. I ended up using a filename of "." and adding a bit of code to clear the filename combobox once the dialog is open.
BUT I can't figure how to clear the filename combobox. I've tried to add hook procedure, enumerate windows and clear text, but this didn't work for me. So, my question is: how can I clear text in the filename combobox of CFileDialog?
Here is a simplified version of my Menu class, where submenus can be inserted arbitrarily deep. I need to add a new functionality "go back to previous menu", which I would like to be activated by entering 0 (universal command for all Menu instances). I considered the Memento Pattern, but that doesn't seem to quite fit. add that functionality to my Menu class.
#include <iostream> #include <cstring> using namespace std; const int END = -1, NO_SUBMENU = 0;
Say a user installs and uses the software for awhile. Then they uninstall it. Client wants the database containing client data to remain behind, in case they ever re-install the software. Which is fine.
So then.. they re-install the software. Client wants them to have the choice to either use the existing database, or to create a new one. When the software fires up, it always checks for the database, and creates one if it's not there. So how can I determine if the instance is a new install, or a current install, given that the database will be there no matter what?
I am in the process of creating a game that has two players machine and person. The player is selected randomly each round. So if the player is selected, he needs to choose a number from 1-9. Then the machine needs to choose another new number either in the same row or colunm.(i figured out how to check against col.and row). Then keep going until someone reaches 31.
I'm stuck on how to add the numbers from previous rounds and have them reflect in the new rounds. While at the same time using the last entered number(last numbers) as a reference has to whether or not the new number is valid.
Ok I created a while loop as suggested. But it is not adding each round like it should. So the question is: What is wrong with the code after the while loop?
while ((x != 0) && (suma < Meta)){ cout << "SUM =" << x + last number << endl; if (player == Person) { x = machinerandomnDigit(last number); sum = sum + x; player = Person; last number = x;
For my assignment I have to have an array with only zeros.
Code: int a[20] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Then I need to send it into a function that makes the array like this
Code: int a[20] = {0,1,2,3,4,5,6, ... , 19}
Which I have done here
Code: int initialize(int a[], int n) { int m = 0; int i; printf("
[Code] ....
Now I need to do the following with the array. I need to take whatever value is in each position and add that value to all of the previous values. like this.
Code: a[3] = a[3] + a[2] + a[1] + a[0]
only for every a[i] I know that I can code this the long way, but I just can't see to be able to find out how to do this a better way.
using namespace std; //class declaration class dayType{ public: int presday;
[Code] ....
So everything works perfectly, well not everything lol. Code compiles successfully without any errors but previous day does not calculate. In a sense that when it asks for number of previous days it returns a blank statement.
For example: Previous number day is: shows nothing
Im trying to do a small program that will create multiples of the previous line *2, and spit out the anwser in seperate lines (as many times as the user wants)
Example if i wrote it in a bad way
2 4 8 16 32 etc.
At this time my code looks likes this, now im planing to get my hands on the IF statment
using System; using System.Collections.Generic; using System.Linq;
if (Choice == 2) { cout << "" << endl << "You follow the light to the end of the hallway, you find your self in a room" << endl << "with natural light coming from a hole in the ceiling." << endl << "" << endl << "You hear the door you just came through, slam behind you!" << endl << "" << endl << "There are three possible directions." << endl << "" << endl << "Do you:" << endl << "" << endl << "1) Go forward" << endl << "" << endl << "2) Go left" << endl
[Code] .....
Ignore the if (Choice == 2) at the beginning, that's linked to some previous code.
I want to make the player go back to the first bit of text but i'm not sure how to do this if they keep choosing to go back and forth from one location.
I first thought of doing it by just putting the text back in after they have chosen the option, but I can't do this infinite times.
I have a program that is reading six characters from a text file, swapping every other character(ABCD would read BADC), and then adjusting their value based on a user's adjusted value input. If the adjusted value is 5 then letter A becomes F.
The final output line should print the initial six characters followed by the final six characters after the swap and encrypt adjustment.
I can only manage to print the final characters. Am I far off thinking I need to use pointers to point to the original character values?
One more thing: instructor wants us to complete this project as simply as possible meaning without the use of arrays, loops, switch statements, etc.
#include <iostream> #include <string> #include <fstream> using namespace std; int main() { //declarations char c1,
Im trying to make a reaction game. I have a grafic that comes up, and the timer starts and when i hit the grafic the timer stops. But my problem is that the Timer doesn't reset.
how to produce a period signal that lasts 0.100 ms that is 35% red and 65% green using a bi-colour LED and the timer module?
while(ReadTimer0() < (unsigned int)165)
Its using this: OpenTimer0(TIMER_INT_OFF & T0_SOURCE_INT & T0_16BIT & T0_PS_1_32);
So does that mean that the period signal is 165 * 32 * 4/32 = 660 = 66%? I really just need to know how to calculate the period signal to produce 35% red and 65% green..
I'm creating a game in which i.need player to.answer.my question within 10 seconds...
So I need a code for this timer... I don't want code to be paused by sleep or delay functions.. But I need that it waits.for 10 seconds.. and if user types answer in between.. it.reads it
And if player.doesn't answers it within 10 sec.. it displays a message
I need to set a timer but still have the program processing info. I have looked into using sleep but when using this all processing stops to my knowledge. I tried to use the settimer method but was having some issues since I am not using a dialog based interface.
I have some value in process memory (not my process). I have address of this value and want to execute function or smth else on changing this value. I think to use timers but I think they are too slow - low resolution(I read smth from 10 to 50 ms) and uses CPU too much. Can you offer me some other solution with not very much cpu usage but with checking variable value nearly 1 to 5 ms.
I am trying to create a five second timer that allows a value to be entered in that span of time. However, if a value is not entered within the five seconds, the timer ends and a value will no longer be able to be entered. I am trying to create a math test that has a five second time limit for equations to be answered.