Guest User

Untitled

a guest
Feb 11th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. char ans = 'y', shape; /*character variables for continue prompt and shape*/
  7. float s, b, h, area; /*floats for side, base, height, and area*/
  8.  
  9. /*continuation loop*/
  10. while (ans != 'n')
  11. {
  12. /*determining shape*/
  13. printf("Please enter the first letter of the shape (S/T): ");
  14. scanf(" %c", &shape);
  15.  
  16. while (shape = 'S')
  17. {
  18. /*Calculating square area based on given length*/
  19. printf("Please enter the side length: ");
  20. scanf("%f", &s);
  21. area = s * s;
  22. printf("The area of the square is %f.", area);
  23. printf("Do you want to continue (y/n)?");
  24. scanf(" %c", &ans);
  25. }
  26.  
  27. while (shape = 'T')
  28. {
  29. /*Calculating triangle area based on given base and height*/
  30. printf("Please enter the base length: ");
  31. scanf("%f", &b);
  32. printf("Please enter the height: ");
  33. scanf("%f", &h);
  34. area = (b * h) / 2;
  35. printf("The area of the triangle is %f.", area);
  36. printf("Do you want to continue (y/n)?");
  37. scanf(" %c", &ans);
  38. }
  39. }
  40.  
  41. system("PAUSE");
  42. return 0;
  43. }
Add Comment
Please, Sign In to add comment