C++ :: How To Get Keypress Within Fixed Amount Of Time

Aug 22, 2013

the program has to accept a keypress. It should wait for some fixed amount of time. If a key is pressed within this time, the program should call a function. If a key is not pressed in this time limit the program should continue its normal execution. The problem with getch() is that it essentially requires you to press a key and it does not allow other instructions to execute until the key is pressed.

View 3 Replies


ADVERTISEMENT

C :: How To Exit Out Of Scanf After Certain Amount Of Time

Oct 25, 2014

I'm trying to make a very simple reaction game where a random number flickers on the screen for a fraction of a second and the user has to then enter the number before another comes on the screen after a random amount of time. However I dont know how i would make it so that the user cannot enter anything after a certain amount of time has passed, below is my code?

Also FYI, clock_start is at 5100 because by the time the program actually gets to scanning in the first number the time is at an absolute minimum of 5050 milliseconds however obviously this is an impossible number to reach due to processing, my machine clocks in at 5080.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
int main(void){

[Code]...

View 6 Replies View Related

C++ :: How To Make Program That Presses Key After Certain Amount Of Time

Mar 9, 2013

Say I want to leave a program running and it stops when I press F9 for instance, I'm looking for something like (and note this is just a generalization).

#include blah
using namespace std;
/wait 2 hours
/key.press = F9
return 0;

View 5 Replies View Related

C++ :: Wrapping Native API Takes Ridiculous Amount Of Time

May 9, 2014

Just wrapping WIN32 is a pain. But I'm learning a shit load about windows in doing so. Designing good software is hard. Even though I can create any gui component I want. I'd have to spend the time to make it synchronous, asnychronous, and learn how to bubble up messages from the windows procedure. Then there is the ordering of components.I'm convinced People who actually used the native apis to make large softwares before autocompletion were INSANE!

View 13 Replies View Related

C++ :: How To Read Input Of Arbitrary Amount Of Numbers Instead Of Specific Amount

Feb 25, 2015

I'm trying to make a program that allows the user to input an arbitrary amount of numbers and finding the largest of all the inputs but I keep having problems with the output.

javascript:tx('
#include <iostream>
using namespace std;
//******************************************
//CLASS COMPARATOR
//******************************************

class comparator {
public:
comparator();

[Code] .....

And regardless of what numbers I enter, I always get the output of 10. Also I got the EOF idea from my textbook so if there is a better way of doing this I'd like to hear it. I don't know any clear ways that looks nice to end the while loop when the user doesn't have any more numbers to enter.

View 3 Replies View Related

C++ :: Pausing The Loop Till Keypress?

Jan 23, 2013

Are there anyways to pause the loop until either LCONTROL or RCONTROL is pressed?

Are there alternatives to stopping LCONTROL and RCONTROL increasing or decreasing counter by a huge sum?

#include <iostream>
#include <windows.h>
#include <conio.h>

[Code].....

View 6 Replies View Related

Visual C++ :: OpenGL - 2D Movement With Respond To Keypress

Mar 4, 2014

I'm trying to implement keyboard controls to move a sphere(Player) with respond to keypress. Currently, when I press any key my character will move to the right by 0.1. How can I move my character with w(up),a(left),s(down),d(right) in their respective directions using respond to keypress?

Code:
class Player {
private:
double x, y;
public:
Player(double a, double b){x=a;y=b;}
void respondtokeypress(char a)

[Code] ....

View 8 Replies View Related

C++ :: Fixed Point Int Min Value

May 14, 2013

I am reading about positive and negative infinity in c++ and i am trying to implement them in a fixed point math arthimethic implementation

I can see that max of a int will be equal to std::numeric_limits<int>::max();
and min value of the int will be equal to std::numeric_limits<int>::min();
in c++

Here as i am defining the int max and int min manually in my fixed point math implementation, my doubt is
int min = -int max; or int min = -int max -1; ?

View 1 Replies View Related

C :: Fixed Point From String

Oct 9, 2013

I have been writing a fixed point library the would handle fixed point numbers with an 8:24 whole/fraction ratio. This has been working quite well but since I have a 24 bit fractional part, it should be able to store 2^(-24).

Code:
long long fraction_part = 0;
long long divisor = 1;

while(*string) {
fraction_part *= 10;
fraction_part += *string - '0';
divisor *= 10;
string++;
}

fraction_part <<= 24;
fraction_part /= divisor;

The issue here is that since the smallest possible fraction is 2^(-24) the divisor could end up needing more than 64 bits and so won't work. I'm not quite sure how else I could do this.

View 7 Replies View Related

C++ :: How To Set Fixed Length For String

May 28, 2013

The input consists of one or more packets followed by a line containing only # that signals the end of the input. Each packet is on a line by itself, does not begin or end with a space, and contains from 1 to 255 characters.

it said 1 to 255 characters

i have to use getline(cin,str);

i tried str[255] but some error happen

View 2 Replies View Related

C++ :: How To Create Unordered Map Of Fixed Size Vectors

Sep 19, 2013

how to create an unordered map of fixed size vectors?

Code:

unordered_map<string, vector<int>> x;

x["mumb 5"][7] = 65; // this does not work since my vector size is not set.

View 7 Replies View Related

C++ :: Shaders Running Slower Than Fixed Pipeline

Feb 3, 2014

While testing some simple examples with glDrawArrays I noticed switching it to shaders can cut my frame rate by over half (from 600- 300). I know I am using a bunch of deprecated code in GLSL right now but I don't expect it to cause that much of an fps drop. I would say it was just my intel graphics chip but if the FFP can handle it I see no reason shaders can't.

--Windows 7 Premum 64-bit
--Intel Core i3 540
--Intel HD Graphics

//Sending 10,000 quads with GLfloats (So Vertices vector has 80,000 elements, currently no indexing).
//Vertices allocated earlier in code, before main game loop

glBindBuffer(GL_ARRAY_BUFFER, vbo);
glEnableClientState(GL_VERTEX_ARRAY );

glVertexPointer(2, GL_FLOAT, 0, 0);
glDrawArrays(GL_QUADS, 0, Vertices.size() / 2);

[Code] .....

The highest Opengl version I can run is 2.1 so 120 in shaders. I know this is a fairly pointless test right now but it is still surprising to see, anything obvious I am missing?

View 19 Replies View Related

C/C++ :: Plotting Points On A Circle With One Fixed Axis

Oct 31, 2014

I am working on a computer program where I need to generate points on a circle. I am familiar with this kind of algorithm:

for(d=0; d<=2*pi; d+=0.01)
{
x = cos(d)*radius;
y = sin(d)*radius;
}

However, due to the specifics of the program I am writing, I need to iterate through a fixed number of points one at a time, like so:

for ( int x = 0; x < blockSize; x++ )
{
y = ???
}

This essentially "fixes" one axis of the circle, since I can't do: x=rx+sin(d)*r.

I have tried simply: "y = sin(d)*radius;" and I get a curved shape, but it's not a circle.

My question then is, how do I get the value of y in this situation, where the x axis is incrementing by 1 through a range of values? Is it mathematically possible?

View 6 Replies View Related

C# :: How To Assign Distance Values To Fixed Graph

Apr 28, 2014

I'm working on a Dijkstra's algorithm with a fixed graph. My question is, how should I go about assign distance values to the graph. The user can start from any node.

View 4 Replies View Related

C++ :: Type Promotion Rules For Fixed Point Class

Jun 19, 2014

I've come across an interesting question involving a fixed-point arithmetic class.

Suppose I've got a template that implements a fixed-point quantity. It has two characteristics: width and number of fraction bits:

Code:
template <typename RAWTYPE, unsigned int FRACBITS>
class Fixed
{
....
};

So if I want a 32-bit value with 12 bits of fraction I can declare:

Code:
Fixed<int32_t, 12> x;

Suppose I've implemented a freestanding operator+() for fixed values, and I want to be able to add different types together:

Code:
template <typename RAWTYPE1, unsigned int FRACBITS1, typename RAWTYPE2, unsigned int FRACBITS2>
???? operator+(Fixed<RAWTYPE1, FRACBITS1> lhs, Fixed<RAWTYPE2, FRACBITS2> rhs)
{
???
}

What is the result type? Obviously, it's up to me to decide this. As reference, consider the type promotion rules for native types:

Code:
short a;
int b;
int result = a + b; In this case, the short value is promoted to the int value, and the addition happens on int.

It would seem a similar rule (go to the wider type) would be appropriate for fixed point. But there is another dimension to the problem, which is the number of fraction bits. Should you go to the wider type? Or the most precise type? Should you endeavor to minimize the number of bits which are discarded? What's the most intuitive rule?

View 10 Replies View Related

C++ :: Passing Fixed Character Array Into Binary File?

Apr 19, 2014

all i want to do is to read a fixed char array sized 4 from user and pass it to Binary File then Print Encrypted content from the the File to the console screen .. but it seems it prints the same input every time .. and i tried everything .. it works fine with integers and strings .. but when it come to char array nothing ..

#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

[Code].....

View 6 Replies View Related

C++ :: Char Vector - Fixed Size Two Dimension Array

Jun 9, 2013

I want to save the char[8][8] // fixed size 2 dimension array

to a vector

such as

vector<?????> temp;

is there anyway to approach this?

View 4 Replies View Related

C++ :: Fixed Point Implementation - Calling A Static Member Function

Apr 25, 2013

I am doing fixed point implementation in c++ which is done by the following code

#ifndef __fixed_point_header_h__
#define __fixed_point_header_h__
#include <boost/assert.hpp>
#include <boost/static_assert.hpp>
#include <boost/operators.hpp>
#include <limits>

[Code] ....

I am getting the error ambiguous overload for âoperator<â in âbeta < ((-5.0e-1) * pi)â

I know the problem the static member function cannot access the members and objects of structs. am i right?

and how to solve this problem, do i need to implement the cossin_cordic function as a non member function.

View 14 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 Get Amount Of RAM Available On PC

Mar 6, 2013

I bet there's a simple function that can return the amount of RAM available on the computer, or perhaps the total RAM on the chip.

Basically I want a way of making sure my program never tries to allocate memory when it can't... I know that Windows should stop this happening anyway but I want to make sure the program can take care of certain things if it happens.

View 3 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 :: Variable That Has All Amount Of Between Two Integer

Feb 25, 2015

I want define Variable that has all amount of between two integer example: 2-4

View 1 Replies View Related

C :: Program That Allow To Enter Certain Amount Of Values

Sep 29, 2014

How to write a code that will let me input how many variables I want.

Write a program that will enable you to enter a certain amount of values

Eg. 4

And then add the corresponding integers. Ex.

Choice: 4 12 34 56 78

The sum of the integers is: 180.

View 4 Replies View Related

C++ :: How To Allocate Huge Amount Of Memory

Mar 8, 2014

I’m writing an application for raw image processing but I cannot allocate the necessary block of memory, the following simple code gives me an allocation error.

double (*test)[4];
int block = 32747520;
test = new double[block][4];

off course with smaller block size (i.e. int block = 327475;) it works fine. Is there an allocation limit? How it is possible to deal with big blocks of memory?

View 2 Replies View Related

C++ ::  How To Create N Amount Of For Loops Without Writing All Of Them Out

Aug 22, 2014

Say I want to exhaust all the possible combinations of 10 variables to find all the solutions to an equation with 10 variables.

I could write out 10 'for' loops, but it would take a lot of space in the code and of course would take a lot of time. Another reason why I want to know this is because it could possible allow me to change the amount of for loops just by changing a number.

I.e., how can I contract the following code into a simple, short form?

for (a[0]=0;a[0]<=9;a[0]++)
for (a[1]=0;a[1]<=9;a[1]++)
for (a[2]=0;a[2]<=9;a[2]++)
for (a[3]=0;a[3]<=9;a[3]++)
for (a[4]=0;a[4]<=9;a[4]++)
for (a[5]=0;a[5]<=9;a[5]++)
for (a[6]=0;a[6]<=9;a[6]++)
for (a[7]=0;a[7]<=9;a[7]++)
for (a[8]=0;a[8]<=9;a[8]++)
for (a[9]=0;a[9]<=9;a[9]++)
if (...)
cout << ... << endl;

View 9 Replies View Related

C/C++ :: Converting Dollar Amount To String

May 18, 2014

I'm quite new to programming and working on an algorithm for the program so we would have to change that into a workable code for our final program.

This is the algorithm teacher gave us for reference (with the functional decomposition):

3.9.3 convertNetPay()
// convertNetPay(in netPay, out netPayString)
char * convertNetPay(float netPay);
void convertNetPay(float netPay, char * netPayString);

Algorithm:
convertNetPay(in netPay, out netPayString)

Declarations: numHuns, numTens, numOnes as integer
OnesTable as array[9] string = {"One", "Two","Three", ...."Nine"}
"One" --> 0
"Two" --> 1
"Three" --> 2
...

[Code] .....

So that goes my entire instruction on the assignment and I will start my code and be probably asking quite a bit of questions!

Here is my code so far:

Spoiler

#include <stdio.h>
#include <stdlib.h>
#include <cstring>
void convertNetPay(float netPay, char *netPayString) {
int numHuns, numTens, numOnes;

[Code] .....

View 9 Replies View Related







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