1<--
2
3
4
in console, when i pres 'a' cursor go down and press'd' the cursor go up. how can i do this in c++?
Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
int main ()
{
int pos = 0;
int numbers[] = {1,2,3,4,5};
char input = 0;
int arrayLength = sizeof(numbers) / sizeof(int);
while(input != 'q')
{
if(input == 'a' && pos < arrayLength-1 )
pos++;
if(input == 'd' && pos > 0)
pos--;
system("cls"); //clears screen
cout << "TYPE A TO GO DOWN, D TO GO UP AND Q TO QUIT!" << endl;
cout << endl;
for(int i = 0; i<arrayLength;i++)
{
if(pos == i)
cout << numbers[i] << " <--" << endl;
else
cout << numbers[i] << endl;
}
input = getch();
}
system("cls");
return 0;
}
|
something like this?
Last edited on
Yes bro!
Thanks very much!