| | |
noob question, answer probably pretty easy, i just don't know where to start
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
I need to set up 2 buttons to take input from the user, that increase and decrease a variable, it doesn't matter which 2 buttons are used, but preferably the up and down arrows. And I also need to have a display of the variable that constantly updates as it is changed by the user.
Basically what I'm doing is creating a simulated datalogging program used on a car's ECU. So the up and down arrows would be controlling my throttle position percentage. And the display would be constantly showing the percentage of throttle the user is controlling. I already have all the forumulas I need for all the other sensors I plan on showing (RPM, KPH, MAP sensor value, Air/fuel ratio etc etc.) I just need some sort of base sample of code of how to take the user's input in this style and have a constantly updating display.
Thanks guys.
Basically what I'm doing is creating a simulated datalogging program used on a car's ECU. So the up and down arrows would be controlling my throttle position percentage. And the display would be constantly showing the percentage of throttle the user is controlling. I already have all the forumulas I need for all the other sensors I plan on showing (RPM, KPH, MAP sensor value, Air/fuel ratio etc etc.) I just need some sort of base sample of code of how to take the user's input in this style and have a constantly updating display.
Thanks guys.
Is this a console program? That kind of thing is better suited to windowed programs, but you can do it easily if you want:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> #include <climits> #include <windows.h> int main() { int count = 0; for ( ; ; ) { if ( GetAsyncKeyState ( VK_ESCAPE ) != 0 ) break; else if ( GetAsyncKeyState ( VK_UP ) & SHRT_MAX ) { if ( count < 100 ) ++count; } else if ( GetAsyncKeyState ( VK_DOWN ) & SHRT_MAX ) { if ( count > 0 ) --count; } std::cout<< std::setw ( 3 ) << count <<"%\r"; Sleep ( 100 ); } }
I'm here to prove you wrong.
•
•
Join Date: Jun 2007
Posts: 6
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> #include <climits> #include <windows.h> using namespace std; int main() { int TPP = 0; for ( ; ; ) { if ( GetAsyncKeyState ( VK_ESCAPE ) != 0 ) break; else if ( GetAsyncKeyState ( VK_UP ) & SHRT_MAX ) { if ( TPP < 100 ) ++TPP; } else if ( GetAsyncKeyState ( VK_DOWN ) & SHRT_MAX ) { if ( TPP > 0 ) --TPP; } std::cout<< std::setw ( 2 ) << TPP <<"% Throttle\r"; Sleep ( 100 ); int RPM RPM = TPP * 74.5 + 750; HANDLE hConsole = GetStdHandle ( STD_OUTPUT_HANDLE ); if ( INVALID_HANDLE_VALUE != hConsole ) { COORD pos = {0, 1}; SetConsoleCursorPosition ( hConsole, pos ); cout << RPM << " RPMs"; }
Okay that throttle stuff worked perfectly, thanks for that
Now though I'm trying to put in my RPM gauge and I can't seem to get it working right. I have a section of code there that puts it on the second line too. I thought I would be able to figure it out myself but I'm having lots of trouble. ![]() |
Similar Threads
- Argorithm: palindromes, write recursive function. (Computer Science)
- Real Yahoo Interview Question And Answer (IT Professionals' Lounge)
- This has to be a simple question to answer. (Visual Basic 4 / 5 / 6)
- noob question (C)
- NOOB question , graphical tiles (C++)
Other Threads in the C++ Forum
- Previous Thread: loop that creates strings?
- Next Thread: Where to get C++ GUI prgramming tutorials?
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






