# writing a C++ program for area of a triangle using Herons formula

• (4 Pages)
• 1
• 2
• 3
• Last »

## 46 Replies - 3912 Views - Last Post: 22 September 2011 - 04:15 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=248196&amp;s=ffedc3eaaab6e6f16bccdf9694859970&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 malmazan1

Reputation: 0
• Posts: 33
• Joined: 22-September 11

# writing a C++ program for area of a triangle using Herons formula

Posted 22 September 2011 - 11:28 AM

My proffesor assigned a this to us. :

The area of a triangle with the sides of lenght a, b, c can be computed by the formula
A= sqrt(s*(s-a)*(s-*(s-c)
where s = (a+b+c)/2. write the program in C++ which will ask for the lenghts of the three sides, and output the area of the triangle.
Heres what i have so far but im stuck( we must also send the output to both screen and and a file) and i cant use looping

```
```
#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
using namespace std;

int main ()
{
string first_name, last_name;
cin >> first_name;
cin >> last_name;
cout << " Hello " << first_name << Last_name << endl;
cout << "Plese enter the three lenghts: " ;
cin >> a >> b >> c ;
double a, b, c;
double s;
double Area;
ofstream outFile; //File the results of calculations

//

//Computations
s = (a + b + c)/2;
Area=sqrt(s * (s-a) * (s- * (s-c) );

//d

cout << "The area of the triangle with sides ... " << endl;
```
```

This post has been edited by malmazan1: 22 September 2011 - 11:36 AM

Is This A Good Question/Topic? 0

## Replies To: writing a C++ program for area of a triangle using Herons formula

### #2 CTphpnwb

• D.I.C Lover

Reputation: 2486
• Posts: 8,533
• Joined: 08-August 08

## Re: writing a C++ program for area of a triangle using Herons formula

Posted 22 September 2011 - 11:32 AM

Are you getting any errors? Why aren't you outputting the Area variable at the end?

### #3 malmazan1

Reputation: 0
• Posts: 33
• Joined: 22-September 11

## Re: writing a C++ program for area of a triangle using Herons formula

Posted 22 September 2011 - 11:38 AM

CTphpnwb, on 22 September 2011 - 11:32 AM, said:

Are you getting any errors? Why aren't you outputting the Area variable at the end?

i dont know what to do next

### #4 CTphpnwb

• D.I.C Lover

Reputation: 2486
• Posts: 8,533
• Joined: 08-August 08

## Re: writing a C++ program for area of a triangle using Herons formula

Posted 22 September 2011 - 11:39 AM

Have you tried to compile and run your code?

### #5 malmazan1

Reputation: 0
• Posts: 33
• Joined: 22-September 11

## Re: writing a C++ program for area of a triangle using Herons formula

Posted 22 September 2011 - 11:45 AM

CTphpnwb, on 22 September 2011 - 11:39 AM, said:

Have you tried to compile and run your code?

no i havent . but i dont understand what u said earlier about outputting the Area part

### #6 CTphpnwb

• D.I.C Lover

Reputation: 2486
• Posts: 8,533
• Joined: 08-August 08

## Re: writing a C++ program for area of a triangle using Herons formula

Posted 22 September 2011 - 11:56 AM

What do you think this line does?
``` cout << "The area of the triangle with sides ... " << endl;
```

### #7 malmazan1

Reputation: 0
• Posts: 33
• Joined: 22-September 11

## Re: writing a C++ program for area of a triangle using Herons formula

Posted 22 September 2011 - 12:06 PM

doesnt it display the area?? or at least thats what i think it does

### #8 CTphpnwb

• D.I.C Lover

Reputation: 2486
• Posts: 8,533
• Joined: 08-August 08

## Re: writing a C++ program for area of a triangle using Herons formula

Posted 22 September 2011 - 12:18 PM

Why would it do that? Where does it output the area variable? All I see is it outputting this text:
The area of the triangle with sides ...

### #9 malmazan1

Reputation: 0
• Posts: 33
• Joined: 22-September 11

## Re: writing a C++ program for area of a triangle using Herons formula

Posted 22 September 2011 - 12:21 PM

oh so i should change it to
```cout << "the are of the triangle ..... << endl;
```

### #10 CTphpnwb

• D.I.C Lover

Reputation: 2486
• Posts: 8,533
• Joined: 08-August 08

## Re: writing a C++ program for area of a triangle using Herons formula

Posted 22 September 2011 - 12:23 PM

Try:
```cout << "the are of the triangle ..... <<Area << endl;
```

### #11 malmazan1

Reputation: 0
• Posts: 33
• Joined: 22-September 11

## Re: writing a C++ program for area of a triangle using Herons formula

Posted 22 September 2011 - 01:04 PM

it says there were build errors???

thats what it said :
---- Build started: Project: lab 03, Configuration: Debug Win32 ------
Embedding manifest...
.\Debug\lab 03.exe.intermediate.manifest : general error c1010070: Failed to load and parse the manifest. The system cannot find the file specified.
Build log was saved at "file://\\tsclient\e\lab 03\Debug\BuildLog.htm"
lab 03 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

### #12 Flipside

Reputation: 12
• Posts: 70
• Joined: 03-July 09

## Re: writing a C++ program for area of a triangle using Herons formula

Posted 22 September 2011 - 01:20 PM

@malmazan1: The problem you had with your original code was that you were only printing out the string "The area of the triangle with sides ... ", exactly as it is written.

As CTphpnwb was saying, you have to print out the value of the variable 'Area' in order to have the actual area be printed. It apppears he just made a typo in the code he provided, so if you copy and pasted that, it wouldn't have compiled.

Try this:
```cout << "The area of the triangle with sides ... " << Area << endl;
```

### #13 malmazan1

Reputation: 0
• Posts: 33
• Joined: 22-September 11

## Re: writing a C++ program for area of a triangle using Herons formula

Posted 22 September 2011 - 01:26 PM

This is how my program looks now adn its still says

------ Build started: Project: lab 03, Configuration: Debug Win32 ------
Embedding manifest...
.\Debug\lab 03.exe.intermediate.manifest : general error c1010070: Failed to load and parse the manifest. The system cannot find the file specified.
Build log was saved at "file://\\tsclient\e\lab 03\Debug\BuildLog.htm"
lab 03 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

```// Maritza Almazan		 CSCI 1380		Fall 2011		Assignment # 3
// Due date: September 23, 2011
//
// This assignment will ask for the user's first adn last name. It will then
// display a brief message for the user on the screen.
// In addition, this program will compute the area and semiperimeter of the
// three lenghts of the triangle. The input will be three numbers adn the
//output wil be the results of the computations.
#include <iostream>
#include <string>
#include <cmath>
//#include <fstream>
using namespace std;

int main ()
{
string first_name, last_name;
cin >> first_name;
cin >> last_name;
cout << " Hello " << first_name << Last_name << endl;
cout << "Plese enter the three lenghts: " ;
cin >> a >> b >> c ;
double a, b, c;
double s'
double Area;
//ofstream outFile;					//File the results of calculations

//Computations
s = (a + b + c)/2;
Area=sqrt(s * (s-a) * (s-B)/> * (s-c) );

cout << "The area of the triangle with sides ... " << Area << endl;

return 0;
}

```

This post has been edited by malmazan1: 22 September 2011 - 01:34 PM

### #14 Flipside

Reputation: 12
• Posts: 70
• Joined: 03-July 09

## Re: writing a C++ program for area of a triangle using Herons formula

Posted 22 September 2011 - 01:37 PM

Quote

------ Build started: Project: lab 03, Configuration: Debug Win32 ------
Embedding manifest...
.\Debug\lab 03.exe.intermediate.manifest : general error c1010070: Failed to load and parse the manifest. The system cannot find the file specified.
Build log was saved at "file://\\tsclient\e\lab 03\Debug\BuildLog.htm"
lab 03 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I'm not exactly sure about this - somebody else may have to jump in here - but try cleaning and rebuilding your project to start.

But first, here's a few things you'll need to fix:

```double s'
```

```string first_name, last_name;
```

```cout << " Hello " << first_name << Last_name << endl;
```

Look at the two spellings of last_name. Variables are case-sensitive.

```cin >> a >> b >> c ;
double a, b, c;
```

Here, you are using the variables a, b and c before you declare them.

### #15 CTphpnwb

• D.I.C Lover

Reputation: 2486
• Posts: 8,533
• Joined: 08-August 08

## Re: writing a C++ program for area of a triangle using Herons formula

Posted 22 September 2011 - 01:37 PM

Close, but you've got typos and you need to declare variables before you use them.
```// Maritza Almazan		 CSCI 1380		Fall 2011		Assignment # 3
// Due date: September 23, 2011
//
// This assignment will ask for the user's first adn last name. It will then
// display a brief message for the user on the screen.
// In addition, this program will compute the area and semiperimeter of the
// three lenghts of the triangle. The input will be three numbers adn the
//output wil be the results of the computations.
#include <iostream>
#include <string>
#include <cmath>
//#include <fstream>
using namespace std;

int main ()
{
double a, b, c;
double s;
double Area;

string first_name, last_name;
cin >> first_name;
cin >> last_name;
cout << " Hello " << first_name << last_name << endl;
cout << "Plese enter the three lenghts: " ;
cin >> a >> b >> c ;
//ofstream outFile;					//File the results of calculations

//Computations
s = (a + b + c)/2;
Area=sqrt(s * (s-a) * (s-B)/> * (s-c) );

cout << "The area of the triangle ... " << Area << endl;

return 0;
}

```