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

Write a program that accepts the following inputs: w, a, s, d, or q. If the user

ID: 3837166 • Letter: W

Question

Write a program that accepts the following inputs: w, a, s, d, or q. If the user types w, the program instantly prints UP. If the user types a, the program instantly prints LEFT. If the user types s, the program instantly prints RIGHT. If the user types d, the program instantly prints DOWN. The user should be able to repeatedly enter these characters for as long as the program runs, printing UP, LEFT, RIGHT, DOWN as required. If the user hits q, the program ends. Nothing other than UP, LEFT, RIGHT, or DOWN is displayed. The program should restore any terminal settings it changes before terminating.

Explanation / Answer

#include <stdio.h>

int main()
{
    int in; //input variable
  
  
    do
    {
        in = getchar(); //accept the input from the keybord
        switch (in)        //used to identify proper output for the iput character
        {
            case 'w' :
                printf("UP " );
                break;
            case 'a' :
                printf("LEFT " );
                break;
            case 's' :
                printf("RIGHT " );
                break;
            case 'd' :
                printf("DOWN " );
                break;
            default :
                break;
        }
    }while(in != 'q');
  
    return 0;
}

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