Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char *argv[])
- {
- char ans = 'y', shape; /*character variables for continue prompt and shape*/
- float s, b, h, area; /*floats for side, base, height, and area*/
- /*continuation loop*/
- while (ans != 'n')
- {
- /*determining shape*/
- printf("Please enter the first letter of the shape (S/T): ");
- scanf(" %c", &shape);
- while (shape = 'S')
- {
- /*Calculating square area based on given length*/
- printf("Please enter the side length: ");
- scanf("%f", &s);
- area = s * s;
- printf("The area of the square is %f.", area);
- printf("Do you want to continue (y/n)?");
- scanf(" %c", &ans);
- }
- while (shape = 'T')
- {
- /*Calculating triangle area based on given base and height*/
- printf("Please enter the base length: ");
- scanf("%f", &b);
- printf("Please enter the height: ");
- scanf("%f", &h);
- area = (b * h) / 2;
- printf("The area of the triangle is %f.", area);
- printf("Do you want to continue (y/n)?");
- scanf(" %c", &ans);
- }
- }
- system("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment