Creating a simple geometric calculator that calculates the area of a triangle

Need help figuring out how to compile the second half of this code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  // Simple Geometric Calculator

#include <iostream>


using namespace std;

int main()
{
  int sideOne = 3;
  int sideTwo = 4;
  int area = 0;
  
  area = (sideOne*sideTwo)/2; //Logic to calculate the area of a triangle
  
  cout<<"The sides of the triangle measure "<<sideOne<<" and "<<sideTwo<<"."<<" The area is "<<area<<"."<<endl;
  
  return 0;
  


the second half of the code the goal is to display pretty much what the first half displays, but the values are multiplied by 5.0 and must display as a double.

the instructions are as followed:

Create a program that calculates and outputs the area of a triangle under two circumstances.
The program will print the area out twice.
For the first output:
The triangle sides measure 3 and 4 at the beginning of the program.
Integers variables will be used to hold the values of the length of the sides and the area of the triangle.
Initially the area variable will hold a value of (be initialized to) zero.
The program then calculates the area of the triangle and places the result of the calculation in the area variable.
The value of the three variables holding the side lengths and area are to then be output as shown below.
For the second output:
Double variables are to be used to hold the values of the length of the sides and the area of the triangle.
The side variables will be initialized to zero.
The program then multiplies the integer length values by five and places them in the double type side variables.
The program then calculates the area of the triangle using the new double type side values and places the result in the new double type area variable.
The value of the double type variables holding the side lengths and area are to be output as shown below.
The output should be with a single decimal place after the decimal point.
The program should produce the following output:

The sides of the triangle measure 3 and 4. The area is 6.
The sides of the triangle measure 15.0 and 20.0. The area is 150.0
a double looks just like an int.
double area = 0.0; //the .0 is just to tell readers. its not needed.

make all the variables doubles.
review:
http://www.cplusplus.com/reference/iomanip/setprecision/
area = (sideOne*sideTwo)/2; //Logic to calculate the area of a triangle
Correct this comment please, the shown formula is only valid if the angle between the two sides is 90 degrees. This is not "a triangle" in the sense of "any triangle", this is a special case, it is a right-angled triangle.
@MikeStgt

area = (sideOne*sideTwo)/2; //Logic to calculate the area of a triangle

Actually, that is the formula for calculating area of a triangle. SideOne would equal the triangle base length and sideTwo would equal the triangle height. They are multiplied then divided by 2. bondo100993 could have named the variables a bit better, but the math comes out the same.

SideOne would equal the triangle base length and sideTwo would equal the triangle height.
Ok, we say "cats" and mean dogs? If in the english language area side one and side two do not denominate the sides of a triangle but its base and hight, the comment I criticized is correct.
(BTW, the base and the hight of the triangle are perpendicular.)
Topic archived. No new replies allowed.