In C language please Write an interactive drawing program th
In C language please!!!
Write an interactive drawing program that will accept characters from the keyboard until ESC is pressed. Redraw the board after every keypress. Use the numpad keys, and switch on the characters 8, 6, 2, and 4 to update x and y variables, then write an asterisk to the global board data. Start at location 15, 15. So, if the user press the 8 key (up), increment y, update board[y][x] = \'*\', then redraw the screen using a nested loop. Use the following code:
char board[30][30];
// Prints the global board using a nested loop
void printboard()
{
int row, col;
for (row = 0; row < 30; row++)
{
for (col = 0; col < 30; col++)
printf(\"%c\", board[row][col]);
printf(\"\ \");
}
}
// main will have something like this inside
loop
// get a character
// switch on character
{
case \'8\':
y--;
break;
//...etc}
//update the board array
// print the board array
endloop
Solution
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = \"\";
char ch;
while (std::getline(std::cin, line) && moveOn)
{
std::cout << line << \"\ \";
// Check for ESC
bool got_esc = false;
for (const auto c : line)
{
if (c == 27)
{
got_esc = true;
break;
}
}
if (got_esc)
break;
}
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int number;
char ch;
bool loop=false;
while(loop==false)
{ cin>>number;
cout<<number;
cout<<\"press enter to continue, escape to end\"<<endl;
ch=getch();
if(ch==27)
loop=true;
}
cout<<\"loop terminated\"<<endl;
return 0;
}

