Thread: creating a program that calculates areas

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    6

    creating a program that calculates areas

    I am working on a school project but am completely stuck and I don't know where to go from here.

    Description:
    Professor Jenkins needs a program that will help him calculate the area of a shape. He would like an option to choose a shape and then be prompted for the necessary information to compute the area of that shape. He also wants to be able to calculate the area for as may shapes as he wants. The shapes Professor Jenkins requires the program to handle are: circles, rectangles, triangles.
    Requirements:
    1. 4 user defined functions (main() and one to handle different shape)
    2. sentinel controlled loop to allow Professor Jenkins to enter as many shapes as he wants.

    This is what I have so far but am at a total loss if this is even right or where to go from here:

    Code:
    //----------------------------------------------------------------------------//
    // Name:                                                     //
    // Student ID:                                                      //
    // Assignment:1                                                               //
    //----------------------------------------------------------------------------//
    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    
    // Function prototypes.
    int displayMenu(int answer);
    float circle(int Radius);
    float rectangle(int length, int width);
    float triangle(int base, int height);
    int main(void)
    {//I have no idea to put in here
     unsigned int counter = 0;
     int option = 0;
     while (option != 4){
     
    }
    // Display the menu to choose a shape or quit. 
    int displayMenu(int answer)
    {
     //declarations
     int choice;
     //assign the variables values
     puts("Choose the shape whose area you would like to compute:");
     printf("%s", "1- Circle, 2- Rectangle, 3- Triangle, 4- Quit the program: ");
     scanf("%d", &choice);
     printf("You chose %d\n", choice);
     return choice;
    }
    float circle(int radius)
    {// I don't know if the float and int are correct for any of these
     int radius;
     float circleArea;
     printf("%s", "Enter radius:");
     scanf("%d", &radius);
     circleArea = (float) 3.14*radius*radius;
     printf("The area of the cirlce with radius %d is %.1f\n", radius, circleArea);
     puts("");
    }
    float rectangle(int length, int width)
    {
     int length;
     int width;
     float rectangleArea;
     printf("%s%s", "Enter length and width of rectangle.");
     scanf("%d%d", &length, &width);
     rectangleArea = (float)length*width;
     printf("The area of the rectangle with length %d and width %d is %.1f\n", length, width, rectangleArea);
     puts("");
    }
    float triangle(int base, int height)
    {
     int base;
     int height;
     float triangleArea;
     printf("%s%s", "Enter base and height of the triangle.");
     scanf("%d%d", &base, &height);
     triangleArea = (float) 0.5*(base*height);
     printf("The are of the triangle with base %d and height %d is %.1f\n", base, height, triangleArea);
     puts("");
    }
    /*
    Copy the results of your program here.
    */
    Last edited by Lukany24; 09-17-2015 at 01:50 AM.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Does Professor Jenkins require the program to be made in C or C++? They're different languages, and this is C, but you've posted it in the C++ section.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 08-01-2012, 01:17 AM
  2. Replies: 7
    Last Post: 10-02-2010, 03:44 PM
  3. Help with program that calculates confidence interval
    By kgrahora in forum C Programming
    Replies: 2
    Last Post: 03-29-2008, 11:45 PM
  4. Program that calculates the value of PI
    By noodles in forum C Programming
    Replies: 7
    Last Post: 09-06-2006, 05:20 AM
  5. C++ Program that Calculates average of three scores
    By dccog in forum C++ Programming
    Replies: 1
    Last Post: 03-28-2002, 12:03 AM

Tags for this Thread