Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A simple question about kbhit() and gatch(): I want to makde a code about switch

ID: 3544510 • Letter: A

Question

A simple question about kbhit() and gatch():


I want to makde a code about switch two pictures by use kbhit() and gatch();


Like when I pressed 'x' , it will showing picture 1 in windows BGI, if not, it will showing picture 2.


There is I tried to do. But it doesnt work:

char ch = getch();

if (kbhit()) { getch();

switch (ch){

case(120) : readimagefile("PIX\flipper_up.jpg", 0, 0, 640, 480);

}


readimagefile("PIX\flipper_down.jpg", 0, 0, 640, 480);


break;}


please tell me the correct answer and explain it. Thank you.

If you need more details just comment there.


A simple question about kbhit() and gatch(): I want to makde a code about switch two pictures by use kbhit() and gatch(); Like when I pressed 'x' , it will showing picture 1 in windows BGI, if not, it will showing picture 2.

Explanation / Answer

Please find working code below, comments are inline. Let me know via comments if you need more help. Hope it helps. Thanks


// Declare the character variable:

char ch;


// Wait till a key is pressed

while (kbhit() != 0)

{

// do nothing

}

// Read the key character

ch = getch();

// Do action as per need

if(ch == 'x')

{

readimagefile("PIX\flipper_up.jpg", 0, 0, 640, 480);

}

else

{

readimagefile("PIX\flipper_down.jpg", 0, 0, 640, 480);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote