Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C by yrwen ( 6 years ago )
#include <stdio.h>
#include <stdlib.h>
#include "shapes.h"

void showHelp() {
    printf("Welcome to my program! \n");
    printf("My purpose is counting perimeter or area of shapes \n");
    printf("Insert number please: (0 for square, 1 for rectangle, 2 for circle)\n");
}

int main() {
    Shapes myShape;
    Detail myDetail;
    unsigned int check;
    double perimeterResult, areaResult;
    
    showHelp();
    scanf("%d", &myShape);
    
    if (myShape < 0 || myShape > 2) {
        printf("Error! Inserted number is wrong.");
        return EXIT_FAILURE;
    }
    
    myDetail.type = myShape;
    
    switch(myShape) {
        case 0: 
            printf("Chosen type is square.\n");
            printf("Insert value of A:\n");
            scanf("%lf", &myDetail.a);
            break;
        case 1: 
            printf("Chosen type is rectangle.\n");
            printf("Insert value of A:\n");
            scanf("%lf", &myDetail.a);
            printf("Insert value of B:\n");
            scanf("%lf", &myDetail.b);
            break;
        case 2: 
            printf("Chosen type is circle.\n");
            printf("Insert value of R:\n");
            scanf("%lf", &myDetail.r);
            break;
    }

    check = checkParams(&myDetail);
    if (!check) return EXIT_FAILURE;
    
    perimeterResult = perimeter(&myDetail);
    areaResult = area(&myDetail);
    
    printf("Result of perimeter is: %lf and result of area is: %lf", perimeterResult, areaResult);

    return EXIT_SUCCESS;
}

 

Revise this Paste

Your Name: Code Language: