Skip to content

Instantly share code, notes, and snippets.

@98chimp
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save 98chimp/fcc2710de134106f8c0f to your computer and use it in GitHub Desktop.

Select an option

Save 98chimp/fcc2710de134106f8c0f to your computer and use it in GitHub Desktop.
Box
//
// main.c
// Box
//
// Created by Shahin on 2015-03-10.
// Copyright (c) 2015 98% Chimp. All rights reserved.
//
#include <stdio.h>
typedef struct {
float height;
float width;
float length;
} Shape;
Shape makeShape(float height, float width, float length);
float calcVolume(Shape box);
float compareVolume(float volume1, float volume2);
int main()
{
float height1 = 3;
float width1 = 4;
float length1 = 5;
Shape box1 = makeShape(height1, width1, length1);
float height2 = 6;
float width2 = 8;
float length2 = 10;
Shape box2 = makeShape(height2, width2, length2);
calcVolume(box1);
calcVolume(box2);
printf("box1 with diemsions height = %f, width = %f, length = %f, produces a volume = %f\n", box1.height, box1.width, box1.length, calcVolume(box1));
printf("box2 with diemsions height = %f, width = %f, length = %f, produces a volume = %f\n", box2.height, box2.width, box2.length, calcVolume(box2));
printf("the volume of box1 is %f times that of box 2\n", compareVolume(calcVolume(box1), calcVolume(box2)));
return 0;
}
Shape makeShape(float height, float width, float length) {
Shape box;
box.height = height;
box.width = width;
box.length = length;
return box;
}
float calcVolume(Shape box) {
float volume = box.height * box.width * box.length;
return volume;
}
float compareVolume(float volume1, float volume2) {
float ratio = volume1/volume2;
return ratio;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment