Hi, im fairly new to c++.I have a variable in my while loop that gets the x position of the mouse and constantly refreshes and outputs to the screen. My problem is that i want to get the exact x position wherever the mouse is when i press the 1 key,, and another value for x when i press the 2 key,, however the output of the variables i want fixed keep changing with x.heres my code:

#include <iostream>
#include <windows.h>
#include <string>
#include <fstream>
#include <math.h>
#include <conio.h>
using namespace std;
int enemyx;
int playerx;
int gameposOffset = 152;
int choice;
int key1;
int x;
int y;



int main()
{



POINT pt;
LPPOINT lpPoint;




HWND currenthwnd;
currenthwnd = GetForegroundWindow();
SetWindowPos ( currenthwnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE|SWP_NOSIZE );
do{


SetActiveWindow(currenthwnd);
if( GetCursorPos( &pt ) != 0)
{
GetCursorPos(lpPoint); 
x = (lpPoint->x)+1; 
y = (lpPoint->y)+1;
}
cout << x <<","<<y;
if (key1=2){
key1=0;
playerx=x;
cout << endl << "Player pos:" << playerx;
}
system("cls");
}while(key1!=1);
return(1);
}

basically its a game i play and its supposed to tell me what degree i should put it to (im not that far in the program though) im still trying to get it to store the playerx and enemyx so that i can use my algorithim to calculate the angle to fire.


so the program should work like this in the future:


put the mouse over character,,, press 1 >> it stores that location,
put the mouse over enemy ,,, press 2 >> it stores that location,

use the algorithim i have to calculate the angle between the 2,,, i have the algorithim working,, i just need your guys help to get the storing of the location.

Edited 6 Years Ago by chubkakes1: n/a

Look carefully at your IF statements. Are your comparison operators correct?

Also, format your code. you'll need to if you want to keep posting because if we can't follow your code, we can't help.

ok i changed the key1=2 to key1==2 but im not quite sure if thats what you meant because the problem still occurs,,
be wary i am quite new to the language and am self teaching.

Yes, that's what I meant, since it was wrong.

And since your description of the problem is vague, I have no other idea. Describe in detail and post you current formatted code and we'll try again.

This article has been dead for over six months. Start a new discussion instead.