| | |
keystroke help
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2005
Posts: 1
Reputation:
Solved Threads: 0
i have read a few threads and am amazed at how much help you get here. I just started learning C++... anyway here is my delema
i am working on a program that you have to enter a number but the seccond number has to be less that the first number, the third number has to be less than the seccond number and the fourth number has to be two less than the third number.
i want to use the keystroke logger so when you type in a number it each keystroke as a vairable and then i can just use this code
if (b < a && c < b && d == c-2){
cout<<"Congrats!! you found a number!";
}
or
if (b<a){
if (c<b){
if (d==c-2){
cout<<"Congratulations you found a number!";
}
}
}
if any one knows of an easier and/or different way please let me know
i am working on a program that you have to enter a number but the seccond number has to be less that the first number, the third number has to be less than the seccond number and the fourth number has to be two less than the third number.
i want to use the keystroke logger so when you type in a number it each keystroke as a vairable and then i can just use this code
if (b < a && c < b && d == c-2){
cout<<"Congrats!! you found a number!";
}
or
if (b<a){
if (c<b){
if (d==c-2){
cout<<"Congratulations you found a number!";
}
}
}
if any one knows of an easier and/or different way please let me know
>if any one knows of an easier and/or different way please let me know
An easier and different way is to just read all of the numbers and compare. At any given point it looks like you only need the current number and the previous number, and how much less the current number has to be than the previous number grows incrementally. I'm thinking of a simple loop:
This can be adapted to reading single digits as well, if your intention is to enter a number such as 5431 and make sure that each digit is less than the previous by a certain amount.
An easier and different way is to just read all of the numbers and compare. At any given point it looks like you only need the current number and the previous number, and how much less the current number has to be than the previous number grows incrementally. I'm thinking of a simple loop:
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main() { const int n = 3; const int increment[n] = {1, 1, 2}; int prev, curr; cin>> prev; for (int i = 0; i < n; i++) { cin>> curr; if (prev - increment[i] < curr) cerr<<"Invalid"<<endl; prev = curr; } }
New members chased away this month: 5
![]() |
Similar Threads
- getting character input with one keystroke (C++)
- Add Favorites with One Keystroke (Windows tips 'n' tweaks)
- keystroke to simulate filling petrol (Pascal and Delphi)
- New machine no keystroke recognition (Troubleshooting Dead Machines)
- INLINECODE Keystroke (DaniWeb Community Feedback)
Other Threads in the C++ Forum
- Previous Thread: Tic Tac Toe AI help, where to reset variables.
- Next Thread: compiler alert
Views: 2443 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






