-
Notifications
You must be signed in to change notification settings - Fork 1
/
GeometricCalculator.cpp
57 lines (50 loc) · 1.93 KB
/
GeometricCalculator.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
Author: TowerX (https://github.com/TowerX/)
Date: October 8, 2020
Purpose: Simple Geometric Calculator > Calculate the area of given sides.
FileName: GeometricCalculator.cpp : This file contains the 'main' function.
*/
// Include required libraries
#include <iostream>
#include <stdlib.h>
#include <iomanip>
using namespace std;
int main()
{
// First Part
// Declare and initialize: Variable sideA of Type int with a value of 3.
int sideA;
// Declare and initialize: Variable sideB of Type int with a value of 4.
int sideB;
// Declare variable area of type int.
int area;
//Taking input values from user
cout<<"\n Enter sides";
cin>>sideA>>sideB;
// Calculate area.
area = (sideA * sideB) / 2;
// Output the value of sideA, sideB and area calculation to the console with some text. Added a new line at the end to separate the content.
cout << "The sides of the triangle measure " << sideA << " and " << sideB << "." << " The area is " << area << "."<< "\n";
// Second Part
// Declare and initialize: Variable dSideA of Type double with a value of 0.
double dSideA;
// Declare and initialize: Variable sideB of Type double with a value of 0.
double dSideB;
//Taking input values from user
cout<<"\n Enter sides";
cin>>dSideA>>dSideB;
// Declare a variable to hold the multiplier value for easy access.
int multiplier;
cout<<"\n Enter multiplier value";
cin>>multiplier;
// Assign the value of sideA multiplied by 5 to the variable dSideA and dSideB respectively. (side * multiplier).
dSideA = (sideA * multiplier);
dSideB = (sideB * multiplier);
// Create a new area variable of Type double called dArea.
double dArea;
// Calculate the area
dArea = (dSideA * dSideB) / 2;
// Output the value of dSideA, sideB and dArea calculation to the console with some text.
cout << setprecision(1) << fixed << "The sides of the triangle measure " << dSideA << " and " << dSideB << "." << " The area is " << dArea << "\n";
return 0;
}