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.
#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;
}
Comments
Leave a comment