summaryrefslogtreecommitdiff
path: root/FixedCode/FixedCode.cpp
blob: e1e9ab5c2c3eabaa0a0cbe7e28a7125848b22354 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//Code by Jordan Harris-Toovy for OIT's CST116 course, October 2021

/*
* Pseudocode:
* DISPLAY Prompt for radius
* GET user input, put into variable radius
*
* DISPLAY Prompt for height
* GET user input, put into variable height
*
* Calculate volume, put into variable volume
* DISPLAY Prompt for volume
*/

#include <iostream>
#include <iomanip>

int main()
{
    float radius = 0.0F, height = 0.0F, volume = 0.0F, pi = 3.14159265359F;

    //Get values from user
    std::cout << "Cylinder volume calculator MK1\n" << "Enter the radius of the cylinder: ";
    std::cin >> radius;

    std::cout << "\nEnter the height of the cylinder: ";
    std::cin >> height;

    //Exit if either input is less then zero
    if ((radius < 0) || (height < 0))
    {
        std::cout << "\nInvald input\n";
        return (1);
    }

    //Calculate volume
    volume = height * pi * radius * radius;

    //Display the volume
    std::cout.setf(std::ios::fixed);
    std::cout << "\n\nThe volume of the cylinder is: " << std::setprecision(2) << volume << std::endl;

    return (0);
}