Answer to Question #258399 in C++ for Stiff

Question #258399

The user must enter a positive integer between 5 and 15. If this number is valid, the






user must also choose between a triangle (T or t) and a square (S or s). Display suitable






error messages if necessary; otherwise, the program must use an asterisk to draw a






triangle or a square of the chosen size and display. Use a Select Case structure to make






the decision. Display appropriate error messages where applicable.

1
Expert's answer
2021-10-29T11:55:20-0400
#include <stdio.h>

void drawTriangle(int a); // todo implement
void drawSquare(int a);  // todo implement

int main(void) {
  int a;
  scanf("%d", &a);
  if (5 > a || a > 15) {
    printf(stderr, "Entered number is not in range(5, 15).");
    return 0;
  }
  char s;
  scanf("%c", &s);
  switch(s) {
    case 'T':
    case 't':
      drawTriangle(a);
      break;
    case 'S':
    case 's':
      drawSquare(a);
      break;
    default:
      printf("Invalid choice!");
      return 0;
  }
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS