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 PM Rate Topic: -----

#1 malmazan1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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-B)*(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;
cout << " Please enter your first name : " ;
cin >> first_name;
cout << " Please enter your last 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) );

//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  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2486
  • View blog
  • 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?

Please use code tags!!!
Was This Post Helpful? 0
  • +
  • -

#3 malmazan1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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

View PostCTphpnwb, on 22 September 2011 - 11:32 AM, said:

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

Please use code tags!!!




i dont know what to do next
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2486
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

#5 malmazan1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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

View PostCTphpnwb, 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
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2486
  • View blog
  • 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;

Was This Post Helpful? 0
  • +
  • -

#7 malmazan1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#8 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2486
  • View blog
  • 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 ...
Was This Post Helpful? 0
  • +
  • -

#9 malmazan1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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;

Was This Post Helpful? 0
  • +
  • -

#10 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2486
  • View blog
  • 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;

Was This Post Helpful? 0
  • +
  • -

#11 malmazan1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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 ==========
Was This Post Helpful? 0
  • +
  • -

#12 Flipside  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • 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;

Was This Post Helpful? 1
  • +
  • -

#13 malmazan1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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;
	cout << " Please enter your first name : " ;
	cin >> first_name;
	cout << " Please enter your last 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

Was This Post Helpful? 0
  • +
  • -

#14 Flipside  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • 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'

' instead of ;

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.
Was This Post Helpful? 0
  • +
  • -

#15 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2486
  • View blog
  • 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;
	cout << " Please enter your first name : " ;
	cin >> first_name;
	cout << " Please enter your last 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;
}


Was This Post Helpful? 1
  • +
  • -

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