types - Mathematics errors in basic C++ program -
I am working with a basic C ++ program to determine the area and perimeter of the rectangle. My program works well for whole numbers, but when I use any number with decimals, it is different I get the impression that I'm leaving something, but since I'm doing a full start I do not know what to do.
Below is the source:
#include & lt; Iostream & gt; using namespace std; Int main () {// declared variable int length; // declares variables for length int width; // declares variable for width wide area; // declared the variable for the field int perimeter; // declares variable for perimeter // details cout & lt; & Lt; "Enter the length and breadth of the rectangle:"; // tells you what cin & gt; & Gt; Length & gt; & Gt; Width; // Length and width of YouTube input; & Lt; & Lt; Endl; // input field = length * width closes; // Count of area of rectangular circumference = 2 * (length + width); // Calculates the perimeter of rectangular crow & lt; & Lt; "Area of rectangle =" & lt; & Lt; Area & lt; & Lt; "Square units." & Lt; & Lt; Endl; // calculates the field cout & lt; & Lt; "Rectangle Perimeter =" & lt; & Lt; Circumference & lt; & Lt; "Units." & Lt; & Lt; Endl; // Calculate Perimeter System ("Pause"); // Deletion before release - Return only 0 for testing purposes; }
type all your int
type variable to Double
or float
. I personally use double
because they have more accurate than float type
.
Comments
Post a Comment