toggle keypress not continual output

i need to create a toggle switch and detect a keypress but not continually output to the console

Update: i do not want code snippets or anything like that just try to point me in the direction of certain functions or things you think i may find useful i just started learning c++ 2 days ago and have been teaching myself this is the way i learn best

// game.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <Windows.h>
using namespace std;
int en;

/*class entity {
bool alive;
bool asleep;
int health;
int x, y;
int affect;
string color;
public:
void set_values(bool, bool, int, int, int, int, string);
void display_values();
};

void entity::set_values(bool a, bool b, int c, int d, int e, int f, string g) {
alive = a;
asleep = b;
health = c;
x = d;
y = e;
affect = f;
color = g;
}

void entity::display_values() {
cout << "alive:" << alive << endl;
cout << "asleep:" << asleep << endl;
cout << "health:" << health << endl;
cout << "x:" << x << endl;
cout << "y:" << y << endl;
cout << "affect:" << affect << endl;
cout << "color:" << color << endl;
}

class enemy : public entity {
double attack;

};
*/

class car {
bool a = false;
bool on = false;
bool lights = false;
int gear;
double speed = 0;
public:
void spd();
void start_stop();
void stop();
void accelerate();
void breaks();
void gear_shift(int);
};

void car::start_stop() {
//toggle attempt
if (a = false)
{
on = true;
a = true;
cout << "car is on" << endl;
}
else if (a=true)
{
on = false;
a = false;
cout << "car is off" << endl;
}
//end toggle attempt
}


void car::accelerate() {
if (on == true)
{
if (speed < 150)
{
speed = speed + 1;
cout << speed << endl;
}
}

}

void car::breaks() {
if (speed > 0)
{
speed = speed - 1;
cout << speed << endl;
}
}

void car::gear_shift(int a) {
gear = a;
}

int main()
{
car cr;
while (true)
{
//needs to detect keypress but not repeatedly send the output
if (GetAsyncKeyState('W') & 0x8000)
{
cr.accelerate();
}
if (GetAsyncKeyState('S') & 0x8000)
{
cr.breaks();
}
if (GetAsyncKeyState('R') & 0x8000)
{
cr.start_stop();
}
}

return 0;
}

Last edited on
Topic archived. No new replies allowed.