C/C++ :: How To End A While Loop After Set Time

Feb 28, 2014

I am trying to make this while loop cut out / self break after 3 seconds. It is part of a simple game I am creating that gives the users 3 seconds to react otherwise it moves on to the next part.

while(1) {
key=getch();
if(key=='a'||key=='k'||key=='g') {
break;
}
}

All I need is it to end after 3 seconds, the rest of the code is working fine.

This sort of thing:

long startTime = System.currentTimeMillis(); //fetch starting time
while(false||(System.currentTimeMillis()-startTime)<10000)
If it IS for C, then I implemented it wrong or something.

View 10 Replies


ADVERTISEMENT

C++ :: Compile-time Loop Loops Wrong

Apr 10, 2013

Consider:
Code: template<unsigned int N>
class Test
{
private:

[Code]....

I just cannot understand why (clearly, we are calling <0, 0>, not <0, 8>). If I replace "N" with 8, it works as expected (at least for the beginning of the loop). I only tested on MSVC.

View 5 Replies View Related

C++ :: Do While Loop Skips Over Input The Second Time Round

Mar 4, 2014

I don't understand why my Do While loop skips over the input the second time round?

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
using namespace std;
//prototype
string reverseInput(string *);

[Code] ....

View 2 Replies View Related

C/C++ :: Same Random Numbers Being Created Every Time Loop Goes Around

May 20, 2013

one of my project involves loop inside loops and creating random numbers. Here is what I have so far:#include <iostream>

#include <string>
#include <cstdlib>
#include <ctime>

[Code]....

so the program will create a random value for the inflow. The idea is that the internal for loop will continue to run until the fill_level of the reservoir, which starts at 0, hits the capacity. The process of simulating how many years (each iteration of the internal for loop representing a year) is to be repeated 10 times by the parent for loop of the water_level simulation for loop.

The problem is that the random number that is supposed to created are the same number. THey are different every time I run it, but they are the same every time the loops repeat to make a new simulation.

View 3 Replies View Related

C/C++ :: Finding Average Time Complexity Of A Nested Loop?

Oct 29, 2014

We were discussing how to find average time complexity of different algorithms. Suppose I've a the following nested loop

for(int i=0;i<n;i++)
{
min = i;

[Code].....

Now the outer loop will iterate N times. the inner loop will always iterate 3 times no matter what the value of N is. so the worst case time complexity should be O(n^2) but what about the average case and the best case? I mean in terms of searching we can figure out and distinguish between the worst,best and average as it depends upon the number of comparisons. But here how can the average and best case be different then the worst case.

View 13 Replies View Related

C/C++ :: Round Robin Execution With Gantt Chart - Arrival Time And Burst Time

Mar 10, 2015

This is a round robin execution. with gantt chart. arrival time and burst time. I think there is an error in my formula to get the right answer,i cant resolve it but my program is running. What is the code or the right formula??

#include<stdio.h>
int main(){
int i,j=0,n,time,remain,flag=0,ts;
int sum_wait=0,sum_turnaround=0,at[10],bt[10],rt[10];
int ganttP[50],ganttStartTime[50];
printf("Enter no of Processes : ");
scanf("%d",&n);
remain=n;

[Code] ....

View 2 Replies View Related

C++ :: How To Use Time For Time Based Movement

May 1, 2013

So I'm trying to learn how to use time for time based movement and what not. I did this only knowing the command time(&variable)

time_t timer;
int I, X;
void main() {
time(&timer);
X=timer;
while(I==5) {

[Code] ......

There's probably some other better way to do it... Obviously but for now I see it as putting current time in X.

start while
take in time constantly until I is 5
constantly asking is time>X(preset time 5 seconds ahead)
if it is
display message and add one to I

Why doesn't this display my message after 5 seconds?

View 1 Replies View Related

C++ :: Time-in Time Out Function?

Mar 18, 2013

make a time-in time-out fuction which extracts the no. of hours and minutes from a string entered by the user.

#include <iostream>
#include <fstream>
#include <string>

[Code].....

View 3 Replies View Related

C# :: Design Time And Run Time

Mar 6, 2014

when we would use add items at design time and when we would add them at run time

does it have anything to do with the page load method? if so, can i type this in source code instead?

View 2 Replies View Related

C :: Loop Does Not Work And Program Quits Without Displaying For Loop Function

Oct 13, 2014

We are making a program--but every time we input a value for scanf, the following for loop does not work and the program quits without displaying the for loop's function. We are not getting any errors.

View 11 Replies View Related

C# :: Use Loop To Load Two Forms Back And Forth Then Stop At Loop 4

Feb 15, 2015

I have tried to submit this topic before but i didn't submit my whole code and it was removed. So here it is. All I am trying to do is load form2 from form1 then back to form1 from form2 for a certain number of times the get out of the loop. I am new to C-Sharp and it seems as though I cant seem to figure out a way to do this.

Here is form1 and form2 code. I have commented out a few things I have tried.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

[Code]....

View 3 Replies View Related

C :: Extra Loop Being Executed In Do-while Loop

Jul 1, 2013

Code:
#include <stdio.h>
#include<ctype.h>
void try5t(){

char choice;
int choiceint;

[Code] .....

Loop is repeated an additional time as shown in the screenshot:

View 9 Replies View Related

C++ :: How Much Milliseconds To Loop Through For Loop

Feb 20, 2014

Given a for loop:

int i;
for(i = 0; i < 1000; i++)
;

How many nanoseconds, or microseconds or milliseconds does it take for each iteration? And why do some use it as a timer mechanism?

View 3 Replies View Related

C/C++ :: How To Change For Loop Into Do While Loop

Apr 19, 2014

I already made a nested for loop into a while loop (below this) and now I'm trying to make the outer for loop into a do while loop, but it's not working.

#include <iostream>
using namespace std;
int main () {
int len;
int j;
int i;

[Code]....

And I can't make this code do the same thing. It stops after one loop, instead of continuing to the end. Why won't the loops continue?

#include <iostream>
using namespace std;
int main(){
int len;
cout << "Enter a number: ";

[Code] ....

View 2 Replies View Related

C/C++ :: Convert A While Loop To A For Loop?

Mar 25, 2012

I need to convert the following while loop:

count = 1;
while (caloriesForItem != 0, count != numberOfItems )
{
cout<<"Enter the calories: ";
cin >> caloriesForItem;
totalCalories += caloriesForItem;
count++;
}

This is what I have come up with:

totalCalories += caloriesForItem;
for (count = 1; caloriesForItem != 0; count != numberOfItems)
{
cout<<"Enter the calories: ";
cin >> caloriesForItem;
count++;
cout << "Total calories eaten today = " << totalCalories << endl;
}

However the output is not the same?

View 6 Replies View Related

C++ :: Why NGrade Comes Out As 0 Every Time

Nov 13, 2013

why nGrade comes out as 0 every time?

Its as if im not inputting the values into the dynamic arrays in int main.

#include <iostream>
using namespace std;
void Calc(int a_anScores[], int a_anPerc[], int a_nTotal){
for( int iii = 0; iii < a_nTotal; ++iii){
a_anScores[iii] = (a_anScores[iii] * (a_anPerc[iii]/100));
}
int nGrade=0;

[Code]...

View 2 Replies View Related

C++ :: How To Add The Time Into Function

Jul 23, 2014

I have created this code with the classes for time and message. Basically the point of this code is to give the information of the sender, recipient, time, and message and im having issues with the time part.

#include <iostream>
#include <string>
#include <ctime>

[Code].....

so when you run this you can see i left a spot for the time but I just cant figure out how to figure out the Time part of this.

View 2 Replies View Related

C/C++ :: Time Conversion Between EST And UTC

Apr 1, 2013

I want to convert time from est to utc. Is there any function for this.

View 3 Replies View Related

C++ :: Coding And Debug Time Per LOC

Mar 23, 2013

I just spent 3 hours writing and debugging 37 lines of code. Is this normal or am I "below average" in coding abilities. I come from a C background and decided to write C++ code that I finally got right as shown below for the specific example:

Code: #include <iostream>
#include <fstream>
#include <string>
#define SPACE_SEARCH 10
using namespace std;

[code].....

I think it was more the learning along the way that consumed atleast 75% of my time for this specific case. But then again, I read that programming always entails learning along the way and so its somehow no excuse for the long time taken in this specific case.

So as a matter of interest, what pace do all of you operate on, on average? i.e. LOC/day, Debugs per day or any other indicator of productivity?

View 3 Replies View Related

C++ :: Simple Calculation Going To 0 Every Time

Aug 8, 2013

I tried to write a simple program to calculate monthly yield, APR, and principle in various directions. Anyway, here's some code to get the APR from the principle and monthly yield. When I run it though, it spits 0 at me every time! What the problem is; the other functions work just fine and the code line for the APR calculation is just what it ought to be - I see neither a math nor tech problem here.

Here is the offending function:

Code:
void calculateAPR() {
int principle, monthlyYield, apr;
cout<<"
Please input the principle:";
cin>>principle;
cin.ignore();

[code]....

View 4 Replies View Related

C :: Subtract Two Time Intervals?

Mar 12, 2014

I am looking for simple code that subtract two time interval. I have time t1=5hour 30 minute and other time in 24 hour format. This code i written but it not working as expected. it not printing 5:30 minute subtract

Code:
main() {
intTime1;
intTime2;
int hour=10;
int minute=5;
int second=13;
int h;int m;
doubleNtime;

[Code] ....

View 3 Replies View Related

C :: Trigger Different Timers At The Same Time

Mar 6, 2015

The issue is that I am trying to run a code which can trigger different timers at the same time. That is, when 3 is typed by the user, the firstimer is triggered. If before expiration another 3 is introduced, the second timer will be launched, and the difference between both triggers will be shown. Under this circumstance, timer_gettime only works once. I tried all the things I could imagine but still, it_value_tv_sec and _nsec return zero after the first expiration.

-Theoretically, and following the manuals, once the timer is restarted the gettime function should work as it does the first time.
-I have also tried to removed the timer and start it again, but in this case the timers are still being triggered, but the gettime outputs(even the first time) are nonsense.

Here is the code I am testing: [CODE]#include<stdio.h>

Code:
#include<signal.h>
#include<time.h>
timer_t firstTimerID;
timer_t secondTimerID;
timer_t thirdTimerID;

[Code] ......

View 1 Replies View Related

C :: Possible To Display Time Continuously

Feb 20, 2013

I created a program to display time continuously so it auto updates every sec but the issue is i cant integrate the code in the main program because to make time update continuously it needs a loop a infinite loop so none of the rest program gets to work. My q is : is it possible to display time continuously and make the rest of program continue normally? like a multi thread program because i want to display time every sec in the bottom of program. By the way this is console app not gui

View 8 Replies View Related

C++ :: Converting Time Between Two Notations

Oct 31, 2013

Write a program to convert the time from 24-hour notation and vice versa. Your program must be menu driven, giving the user the choice of converting the time between the two notations. Furthermore your program must contain at least the following function : a function to convert the time from 24-hour notation to 12-h notation, a function to convert the time from 12-hour notation to 24-hour notation, a function to display the choices, function(s) to get the input, and function(s) to display the results.

View 2 Replies View Related

C++ :: Get Full Time Without Seconds

Jun 21, 2013

I have a code to check the last time modification of a file using "gmtime". Is it possible to remove the seconds in the result?

Here is my code:

struct tm* clock;// create a time structure
struct stat attrib;// create a file attribute structure
stat("test.txt", &attrib);// get the attributes of afile.txt
clock = gmtime(&(attrib.st_mtime));// Get the last modified time and put it into the time structure

View 6 Replies View Related

C++ :: Destructor Called 2 Time

Apr 8, 2014

Why in this code the destructor is called 2 time? How can i avoid it?

int _tmain(int argc, _TCHAR* argv[]) {
Elenco e1;
std::cout << "Test 2" <<std::endl;
std::cout<<e1.size()<<std::endl;

[Code] ....

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved