C++ :: Calculating Area Of A Triangle Using Heron Formula

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


ADVERTISEMENT

C/C++ :: Built In Formula For Calculating The Range Of Float And Double?

Oct 26, 2013

I want to get the direct formula for calculating the range of double and float datatypes in c,if any.

View 1 Replies View Related

C/C++ :: Area Of Triangle Calculator?

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

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 View Related

C :: Calculates Area Of A Triangle - If Statement

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

C++ :: Program To Find Area Of Triangle?

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

C++ :: Compute Area Of A Triangle Using Cross Product

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

C/C++ :: Calculating Hypotenuse Of A Triangle

Apr 3, 2014

I wrote a function to calculate the hypotenuse of a triangle. My code looks fine but when i enter the two sides it does not give out the right answer. I really don't know what to do.

#include <stdio.h>
#include<Windows.h>
#include<math.h>
double hypotenuse(double side1, double side2);
int main(void){
double side1, side2, hyp;

[Code] .....

View 8 Replies View Related

C/C++ :: Find Triangle In Array Of N Triangles Which Has Largest Area

Apr 6, 2015

How to find triangle in an array of n triangles which has the largest area?

#include <stdio.h>
#include <stdlib.h>
#include<math.h>
typedef struct {
double x,y;

[Code] .....

View 14 Replies View Related

C++ :: Compound Interest Formula

Jun 21, 2013

Equation for compound interest. The interest is supposed to be $43.34 according to the book, I am ending up with around $35. The actual equation is amount = principal * (1 + rate/t)^t where t = number of times compounded per year. I still have to go through and clean up all the code I just want the formula working first.

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main () {
float princ, rate, comp, savings, interest, rates, year;

[Code] .....

View 2 Replies View Related

C/C++ :: Quadratic Formula - If Statement Being Ignored

Jan 28, 2014

We are suppose to build a program to do the quadratic formula, which isnt really a issue. my issue is i have a if else loop and my if is being ignored.

what i want it to do is is state that if the (b * /> - 4(a)© is a negative, then it prints out stating it cant do this.

note: i know that i can use the i number system but we have been asked to not too and to do this instead.

here is my code

#include <stdio.h>
#include <math.h>
int main() {
float a, b, c, d, e, f, g, h, i; /* i would love to figure out a way to do this without so many variables*/

[code]....

View 3 Replies View Related

C++ :: Compound Interest Formula Coding

Sep 24, 2014

Im having problems coding this
A = P(1 + r/n)nt

//Declared test cases
float principal = 200000.00, annualInt = 0.03;
float years = 10.0;

float calcInterest1(float principal, float years, float annualInt) {
float interest1;
float nt = annualInt*12;
float A = principal+annualInt;//Accrued Amount
interest1 = (A = (principal*(1+years/100))pow(nt));// A = P(1 + r/n)nt
return interest1;
}

View 1 Replies View Related

C++ :: Creating A Loop To Calculate Formula?

Mar 21, 2014

I am trying to create a code and cannot get the following part to work :

for (int n = 0; n = timesteps; n++)
{
n = n + 0.1 ;
cout<< "timesteps"<< n << endl ; //print time step value =0.1
for (int j = 0; j < nodesinx; j++)
{
T[j][n+1] = T[j][n] + 0.16 * (T[j][n] - 1[n] - 2[T[j][n] + T[j] + 1[n] ; //equation
n= n + 0.1 ;
cout<< "temperature" << T[j][n+1] << endl;
T[j][n+1] = 0.0 ;
}
}

View 1 Replies View Related

C/C++ :: Define The Formula Of Prime Numbers?

Jul 27, 2014

It is possible to define the formula of prime numbers in C++ language?

View 1 Replies View Related

C :: Math Function Using Exponential Growth Formula

Sep 3, 2013

Its a basic math function using the exponential growth formula which is correct but the computer is not outputting the right numbers.

Code:
#include <stdio.h>
#include <math.h>
int main() {
int blanketsquares, num1, num2, blanket,remainder;

[Code] .....

View 6 Replies View Related

C++ :: Quadratic Formula Loss Of Significance And Simplification

Feb 16, 2015

write codes that could solve a quadratic formula, and my codes are like this:

#include <bjarne/std_lib_facilities.h>
int main()
{
cout << "Enter the coefficients of a quadratic polynomial a*x**2 + b*x +c:
";
cout << " a? ";
double a;
cin >> a;
cout << " b? ";

[code]....

Which runs perfectly, but I have 2 questions:

1. How to simplify these code? On the assignment sheet the professor wrote about using void solve_linear(double b, double c); and void solve_ quadratic (double a, double b, double c);which I currently dont understand how these works. He asked us to write a well-encapsulated (as short as possible) program.

2. These are for extra points: the precision problem of floating numbers: professor asked us to find a way to get the precise answer of it, like this: Enter the coefficients of a quadratic polynomial a*x**2 + b*x +c:
a? 1
b? -20000
c? 1.5e-9
Trying to solve the quadratic equation 1*x*x + -20000*x + 1.5e-09 == 0
Using classical formula: Two roots, x = 20000 and x = 0
Using stable formula: Two roots, x = 20000 and x = 7.5e-14

My guess is that
A. Using code like if(x1*x2=a/c) to check if numbers were approximated.
B. Somehow determine the larger one in x1 and x2.
C. Somehow use that larger one to do something

View 2 Replies View Related

Visual C++ :: Totals Or Formula To Calculate Is Not Working?

Sep 19, 2014

My code is below:

Total Interest ends up as my last Monthly Payment amount instead of adding up all Interest Paid - What am I doing wrong?

Total Paid isn't calculating correcly either - What am I doing wrong?

I suspect both are very similar problems. I've tried several different calculations, but cannot figure this out.

#include <iostream>
#include <cmath>
using namespace std;
double GetMonthlyIntrest (double OpenBalance,double rate);
bool ContinuePgm();
int main () {
double StartingBalance,rate,amount,OpenBalance,IntPmt,TotalInt=0.0,GrandTotal=0.0;

[code]...

View 3 Replies View Related

Visual C++ :: Writing Formula For Standard Deviation?

Apr 17, 2013

How to write a formula for standard deviation but im having a hard time ?

View 2 Replies View Related

C++ :: Function That Computes Result Of Formula For Two Sets Of Inputs

Nov 14, 2013

I'm currently writing a program and a portion of it needs to have a function that computes the result of a formula for two sets of inputs. It then has to calculate and display the difference between the two results.

I have code that takes the input from the user and converts it to the type that I need. In this case we are talking about latitudes and longitudes that will be converted to degrees, then to xyz coordinates.

View 1 Replies View Related

C++ :: Lagrange Interpolation Formula - Substitute Values Into Power

May 7, 2013

I did a function for lagrange interpolation formula. However i`m stuck on how do i substitute values into the power. Here is my code snippet :

for(int i=1;i<getSecretShare+1;i++) {
//calculateValue=getSecret+(10*p)+(2 * pow(p,2));
int storeThreshold=getThreshold;
calculateValue=getSecret+(10*i)+(2 * pow(i,2));
calculateFinalValue=calculateValue % 17 ;
cout<<"the calculated value is "<<calculateFinalValue<<endl;
}

The formula that i want to implement is that a + a1x^1 + a2x^2 + a(t-1) ^t-1

I have gotten the substitution of the x value out. However, i am stuck on how do i calculate the values according to the threshold which the user keys in. For example if the user keys in 3.

It will into account the no. of shares to generate which is for example 5 in this case, then it will then take into account the threshold keyed in , which is 3, i will then calculate using the formula using the no. of shares and also threshold.
if the threshold is 3 and the number of shares to generate is 5. I should have the following:

y(1) = 13 + a1(1)^1 +a2(1)^2
y(2) = 13 + a2(2)^1 +a2(2)^2

the power depends on the threshold which is t-1, 3-1 =2

So I will have to generate two a values based on that and also calculate them according to the power that is dependent on the threshold the first value being to the power of 1 and the 2nd being to the power of 2 if the threshold is 4.

Then I will generate 3 a values and then calculate them :

y(1) = 13 + a1(1)^1 + a2(1)^1 + a3(1)^3

and so on..

View 4 Replies View Related

C :: Find Factorial Of Any Number Greater Than Zero And Use Gosper Formula To Approximate It

Feb 24, 2013

I was given a question in my programming class to create a program to find the factorial of any number greater than zero and to use Gosper's formula to approximate it.

Code:
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
double equation(int n);
int

[Code] ....

View 2 Replies View Related

C/C++ :: Making Offsets - Addressing Formula Of Straight Forward N Dimensional Array

Apr 12, 2014

I know how to make offsets/addressing formula of a straight forward N Dimensional array but how to make an offset and a storage allocation space for something tricky like:

1. A lower and upper triangular matrix?
2. A band matrix?
3. Making an offset for ragged arrays which have different row lengths?
4.A upper/lower triangular matrix using ragged arrays?

This is not for an assignment but preparation for an exam. I don't know how to go about on finding these out.

View 14 Replies View Related

C++ :: Calculate Area Of Circle Without Pi

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

C/C++ :: Program That Uses The Radius To Get Area?

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

C++ :: Area And Volume Of Cylinder?

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

C++ :: Calculate Area And Volume Of Cylinder?

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







Copyrights 2005-15 www.BigResource.com, All rights reserved