944,000 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3058
  • C++ RSS
Jan 26th, 2005
0

keystroke help

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
iseekknowledge is offline Offline
1 posts
since Jan 2005
Jan 27th, 2005
0

Re: keystroke help

>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:
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. const int n = 3;
  8. const int increment[n] = {1, 1, 2};
  9. int prev, curr;
  10.  
  11. cin>> prev;
  12. for (int i = 0; i < n; i++) {
  13. cin>> curr;
  14. if (prev - increment[i] < curr)
  15. cerr<<"Invalid"<<endl;
  16. prev = curr;
  17. }
  18. }
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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Tic Tac Toe AI help, where to reset variables.
Next Thread in C++ Forum Timeline: compiler alert





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC