c++ console program (simple but awkward)
Hi all,i'm still a newbie (still working with console...) so please keep it as simple as possible :3
So,i've been trying to do a (seamlessy) simple program,but neither I neither my teacher have a clue on how to do that.
The purpose of the program is: taking a laugh/useless program.
What it should do: it asks you any character,then proceeds to spam it using a cycle. However,if you press any key during the cycle,the spammed character will be swapped to the key pressed.
-IMPORTANT-
It has to don't stop the cycle running.
-hint-
kbhit() does a similiar feature,however,it just captures if you've pressed or not a key during the cycle,while i need it to set the key to a variable.
This is the starting code:
-hint2-
using getc/getch/getchar () will result the cycle to stop.
-curiosity-
this could be used to actually make something useful: a program to do different actions based on keypresses.
An example of this would be a wasd program,which tells where a subject would go through spamming words in the console.
-explanation-
While the code i provided does this:
I'd need it to do something like this:
Hope someone can help me out :3
So,i've been trying to do a (seamlessy) simple program,but neither I neither my teacher have a clue on how to do that.
The purpose of the program is: taking a laugh/useless program.
What it should do: it asks you any character,then proceeds to spam it using a cycle. However,if you press any key during the cycle,the spammed character will be swapped to the key pressed.
-IMPORTANT-
It has to don't stop the cycle running.
-hint-
kbhit() does a similiar feature,however,it just captures if you've pressed or not a key during the cycle,while i need it to set the key to a variable.
This is the starting code:
Code:
#include <stdlib.h>
#include <iostream>
using namespace std;
int main ()
{
int y=0;
char x;
cout<<"gimmie character to spam";
cin>>x;
while (y==0)
{
cout<<x<<" ";
}
system("pause");
return 0;
}
using getc/getch/getchar () will result the cycle to stop.
-curiosity-
this could be used to actually make something useful: a program to do different actions based on keypresses.
An example of this would be a wasd program,which tells where a subject would go through spamming words in the console.
-explanation-
While the code i provided does this:
Code:
x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x ...
Code:
x x x x x x x x x x x x x x x x x x x x x x x x x a a a a a a a a a a a a a a a a a a y y y y y e e e e e e e e e e e e ...

