C: Calculate Floor Area Based On User Input.

 https://github.com/pereiradaniel/beginning_c/blob/master/ch2/exercises/2_2/exercise2_2.c

// Exercise 2-2

// Write a program that prompts for input of the length and width of a room in
// feet and inches, and then calculates and outputs the floor area in square yards with two
// decimal places after the decimal point.

#include <stdio.h>

double getYards(int feet, int inches)
{
    double result = (double)feet * 0.3333333 + (double)inches * 0.02777778;
    return result;
}

int main(int argc, char* argv[])
{
    int feet = 0, inches = 0; // vars for storing user input
    double length = 0, width = 0; // room dimensions in yards

    // Prompt user for length and width of a room in feet and inches.
    printf("ROOM LENGTH\n-----------\nEnter room length:\nFEET: ");
    scanf(" %d", &feet);
    printf("INCHES: ");
    scanf(" %d", &inches);

    length = getYards(feet, inches);

    printf("\nROOM WIDTH\n----------\nEnter room width:\nFEET: ");
    scanf(" %d", &feet);
    printf("INCHES: ");
    scanf(" %d", &inches);

    width = getYards(feet, inches);

    printf("\nRoom area: %.2f square yards.\n", length * width);

    return 0;
}
https://github.com/pereiradaniel/beginning_c/blob/master/ch2/exercises/2_2/exercise2_2.txt
==346== Memcheck, a memory error detector
==346== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==346== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==346== Command: ./exercise2_2
==346==
ROOM LENGTH
-----------
Enter room length:
FEET:10
INCHES:5

ROOM WIDTH
----------
Enter room width:
FEET:5
INCHES:2

Room area: 5.98 square yards.
==346== 
==346== HEAP SUMMARY:
==346==     in use at exit: 0 bytes in 0 blocks
==346==   total heap usage: 2 allocs, 2 frees, 2,048 bytes allocated
==346==
==346== All heap blocks were freed -- no leaks are possible
==346==
==346== For lists of detected and suppressed errors, rerun with: -s
==346== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Popular posts from this blog

C programming and relevancy

Shakespeare AI: My lady is more beauteous than a rose.

C: Temperature Conversion With Main Repeat