C++ :: Calculating Area And Perimeter
Sep 28, 2014
I am having trouble with my C++ program. My program asks the user to enter any number greater than 0 and less than 20, and if the user enters any number(s) outside the acceptable range, the output should display:
input outside of exceptable range > 0 and < 20
length: 1 width: 1 area: 1 perimeter: 1
But in my program, this output displays no matter what the user types (even if the numbers are in the acceptable range, when it should be displaying the length and width the user enters and also displaying the calculated perimeter and area whenever the user enters number(s) in the acceptable range. Here is my code:
#include <iostream>
using namespace std;
float class_rectangle_area();
float class_rectangle_perimeter();
float class_rectangle_length();
float class_rectangle_width();
[Code] .....
View 4 Replies
ADVERTISEMENT
Dec 10, 2014
Below is what i have so far. My main issue is outputting the area and perimeter of the given coordinates as i need the final coordinate to connect up to the first coordinate. I've tried doing that using numberOfcorners but it says "the expression must have integral or enum type"
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <math.h>
using namespace std;
int main() {
float ArrayX[10];
float ArrayY[10];
float numberOfcorners;
[Code] .....
View 3 Replies
View Related
Jan 28, 2013
Write a program that prompts the user to input the length of a rectangle and the width of a rectangle and then displays the rectangle's area and perimeter. The program should be broken down in 3 parts:
1. Input the length and the width (two input statements)
2. Calculate the area & perimeter (results should be saved in variables
3. print results.
Format the output so the user can easily read the results. Use the tab escape so its easy to read.
---------------------------------------------------------------
So here's what I have so far. I have been stuck for two days
#include iostream
using namespace std;
int main () {
int double length;
int width;
int area;
int perimeter;
[Code] ....
I dont want to get a zero for not turning this in...
View 14 Replies
View Related
Oct 18, 2013
How would this look like in C? Develop an application to calculate the area and perimeter of geometric shapes. First the user is asked to enter a letter representing the shape. We use C for circle, R for rectangle and S for square. After the user chooses the shape, the program prompts for the appropriate dimensions of the shape accordingly.
For instance, if the user has chosen a square, the program will ask for a side. If it's a circle, the program will ask for radius. If it's a rectangle, it will ask for length and width. Upon receiving the appropriate dimensions, the program will calculate the area and the perimeter of the requested shape and print it on the screen. And again, the code will ask for another letter. If the user enters 'Q' the program terminates.
Please Enter Shape (C: Circle, S: Square, R: Rectangle Q:quit) >S
Please enter the side of the square > 8
The area is 64 and the perimeter is 32
Please Enter Shape (C: Circle, S: Square, R: Rectangle Q:quit) >R
Please enter the width of the rectangle > 5
Please enter the length of the rectangle > 7
The area is 35 and the perimeter is 24
Please Enter Shape (C: Circle, S: Square, R: Rectangle Q:quit) >Q
View 1 Replies
View Related
Nov 7, 2014
I need to calculate the area of a triangle using heron's formula. I wrote the code below and i need to modify it so that a user is required to keep entering the three side until he/she decides to stop. If the three sides entered make an invalid triangle, the user is required to re-enter the values until valid triangle is formed. Then the area is displayed.
#include <iostream>
#include <cmath>
using namespace std;
int main(){
double a,b,c=0;
double s,A=0;
[Code] .....
the screen output should like this:
Enter three sides of a triangle: 0 1 2 Error!
Re-enter three sides of a triangle: -1 1 2 Error!
Re-enter three sides of a triangle: 3 4 5 => 6
Continue (y/n)? y
Enter three sides of a triangle: 1 1 2 Error!
Re-enter three sides of a triangle: 6 8 10 => 24
Continue (y/n)? n
Done!
Please note that Continue (y/n)? only displayed after a valid triangle is formed. Otherwise, the user needs to re-enter sides until it's valid.
View 1 Replies
View Related
Jun 26, 2013
I intended to compute perimeter of a triangle. The problem is the initial value for the triangle.
#include <iostream>
#include <cmath>
using namespace std;
struct Point{
double x;
double y;
[Code] ......
I expect to get 0 for triangle1, but I get some strange value...
Here is the result
Type x for point1 : 1
Type y for point1 : 1
Type x for point2 : 3
Type y for point2 : 1
Type x for point3 : 1
Type y for point3 : 3
The perimeter of the triangle1 is : 2.82843
The perimeter of the triangle2 is : 6.82843
View 2 Replies
View Related
Mar 22, 2013
I was given an assignment for class to calculate the area of a circle using only the radius as a user input and not using Pi in the code. I need to do this by calculating the areas of a series of rectangles under the curve and adding them together. Using nested loops to continuously reduce the size of these rectangles until the approximated area value is within a margin of error less than 0.1%.
Code:
#include<iostream>
#include<cmath>
using namespace std;
int main ()
[Code] .....
View 7 Replies
View Related
Nov 16, 2014
I was asked to build a small program to calculate the are of a Triangle but my code must have some problem.. />
#include "stdafx.h"
void main()
{
int a,b;
[Code]....
I get this errors:
-warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
-warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
View 4 Replies
View Related
Apr 28, 2012
How can i come up with a program that uses entered radius of a circle to find its area
View 1 Replies
View Related
Apr 27, 2013
I would like to calculate area and volume of cylinder but radious and height should be integer, float and double.
View 14 Replies
View Related
Apr 27, 2013
I would like to calculate area and volume of cylinder but radious and height should be integer, float and double. How can i do?
View 9 Replies
View Related
Jun 10, 2013
I am currently learning "if statements" while doing a program that calculates the area of a triangle. My problem is that the result is always "0". I am pretty sure the problem lies within my math, but how I have set it up wrong.
I am using Heron's Formula. Here it is for reference:
area=sqrt(s(s-a)(s-b)(s-c)) where s=(a+b+c)/2
Code:
#include <stdio.h>
#include <math.h>
int main () {
float area, sideA, sideB, sideC, halfP;
[Code] ....
View 4 Replies
View Related
Feb 17, 2014
#include <iostream>
#include <cmath>
using namespace std;
//prototypes for all separate functions
int chooseFunc(int);
int chooseMethod(int);
int numRect(int);
[Code] .....
It seems that my program will ask the user for the number of rectangles and trapezoids but will fail to compute the area under the curve from the user input. Therefore, I believe I have a logical error somewhere or I'm forgetting to call something somewhere.
View 1 Replies
View Related
Dec 6, 2013
I'm building a pretty basic calculator program that calculates the area of generic shapes (triangles, rectangles, and squares); for some reason though, my program is having troubles as soon as it hits the if/else code in the int main section. When I enter triangle, rectangle, or square, it just spits back out the "That's not one of the options. Please re-enter and try again." error line I created. When I isolate and run just the stuff inside the if/else statements it works great, but why it won't just understand my if (shape == triangle).... .
Code:
#include <iostream>
using namespace std;
class figure {
protected:
double x, y;
[Code] ....
View 2 Replies
View Related
May 26, 2013
i have written a program to find area of triangle, but i meet some errors,
//******area of triangle******//
#include<iostream>
using namespace std;
[Code].....
View 1 Replies
View Related
Aug 6, 2014
I need to calculate the average brightness of a defined area in a bitmap. Is there a way to select the area which a watermark is going to be applied to, and then find it's average brightness?
I have the below code, but at the moment Color pixel is displaying 0, 0, 0 for RGB, I believe i'm doing it wrong, I have tried to use this as a reference but use part of the image instead of the entire image.
See Company Watermark region!
public void addWatermark() {
Image source = Image.FromFile("C:UsersMartyn BallDesktopImages 38.JPG");
Image watermark1 = Image.FromFile(Glb_venueWatermark);
Image watermark2 = Image.FromFile(Glb_companyWatermark);
//Get width and height of image
int sourceWidth = source.Width; int sourceHeight = source.Height;
[code]....
View 11 Replies
View Related
Mar 31, 2015
[URL] .... This is what I have so far, and it isn't incorrect, but how to improve this or make it more accurate?
// subtracting the area of two circles from a rectangle
#include <iostream>
using namespace std;
int main() {
cout << "This program is designed to calculate the area of a rectangle, to exclude the area of 2 circles that have been placed inside of the rectangle." << endl << endl;
[Code] .....
View 12 Replies
View Related
Mar 15, 2014
I am writing a program to calculate a rectangle's area.
Eg.
Enter top left point: 1 1 (User input)
Enter bottom right point: 2 -1 (User input)
Top Left x = 1.000000 y: 1.000000
Bottom Right x = 2.000000 y: -1.000000
Area = 2.000000 (Program output)
It keeps on prompting me my variable r is being used without being initialized, when I think I already did so.
Code:
typedef struct {
double x;
double y;
} Point;
[Code] ....
View 8 Replies
View Related
Feb 15, 2013
how can i input lines at a specific area in my file. please provide code
View 3 Replies
View Related
Sep 27, 2014
I trying to write a program that calculates the area and circumference of a circle.
This is what I wrote so far.
Code:
#include <stdio.h>
void main()
{
int r;
int pi=3.14159265;
float cir,area;
printf("
enter the radius of the circle ");
[Code]...
the Problem is when I input the radius the answer I get is zero regardless of the the radius. Am I missing something?
View 4 Replies
View Related
Apr 1, 2013
Area of the room. Your task is to write a program that will find the area of room in a given square maze.
Note. Use recursion for solving this problem.
Input:
First line contains only one number N (3 <= N <= 10).The number that describes the size of the square maze.
On the next N lines maze itself is inputed ('.' - empty cell,'*' - wall).
And the last line contains two numbers - the row and column of the cell in the room those area you need to find.It is guaranteed that given cell is empty and that the maze is surrounded by walls on all sides.
Output:
Output only one number - total amount of empty cells in the selected room.
View 8 Replies
View Related
Feb 11, 2013
B. Circle in a Square Write a C++ program that will ask the user to enter the area of a square. Then the program will display the biggest area of a circle that will fit in a given square. Using math.h library is not allowed.
View 1 Replies
View Related
Jan 8, 2015
I have to write some cpp program which computes area of a triangle using cross product,we give 3 vertices as R2 and 3 edges as double.
I am beginning like this;
#include <iostream>
#include "R2.h"
#include <cmath>
using namespace std;
double area ( R2 *A,double *z)
[Code] .....
View 5 Replies
View Related
Feb 1, 2013
write a C++ program to find the area of a square, input the length of the side, and output your answer to the screen.
View 3 Replies
View Related
May 4, 2015
question: Finding pi through computing area of a quarter circle
my code
PHP Code:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
int sum=0;
double PI,h,x;
[Code] .....
View 14 Replies
View Related
Jan 24, 2015
So for my assignment, I have to write code to calculate the surface area and volume for a rectangular prism that involves the use of functions. I made the program without functions and it works perfectly but as I'm putting in the required functions, it conversely made it non-functional, ironically. How to call functions correctly and the online book we're using now is confusing me even more.
Code:
#include <stdio.h>
#include <math.h>
int main(void) {
double x1, x2, x3, x4, x5, x6, x7, x8 = 0;
double y1, y2, y3, y4, y5, y6, y7, y8 = 0;
double z1, z2, z3, z4, z5, z6, z7, z8 = 0;
double length, width, height=0;
[Code]....
And here is the version I'm using to test it (without the need to input the individual coordinates).
Code:
#include <stdio.h>
#include <math.h>
int main(void) {
double x1, x2, x3, x4, x5, x6, x7, x8 = 0;
double y1, y2, y3, y4, y5, y6, y7, y8 = 0;
double z1, z2, z3, z4, z5, z6, z7, z8 = 0;
double volumePrism, surfaceArea =0;
[Code]...
View 3 Replies
View Related