Jump to content


C2064 error


3 replies to this topic

#1 CollegeProginTraining

    New Member

  • Members
  • Pip
  • 4 posts

Posted 05 October 2006 - 01:41 AM

I am having some problems with this program.

#include <iostream>
#include <math.h>
using namespace std;
int main (){
	double A, s, SideB, SideC, SideD;
	cout << "Please enter the value of Side A: ";
	cin >> SideB;
	cout << "Please enter the value of Side B: ";
	cin >> SideC;
	cout << "Please enter the value of Side C: ";
	cin >> SideD;
	s = (SideB + SideC + SideD)/2;
	A = sqrt (s(s-SideB)(s-SideC)(s-SideD));
	cout << "You entered: " << SideB << "Side A + " << SideC << "Side B + " << SideD << " Side C " << A << " = area." << endl;
	if (SideB + SideC > SideD, SideC + SideD > SideB,SideD + SideB > SideC)
		A = sqrt (s(s-SideB)(s-SideC)(s-SideD));
	else
		cout << "The numbers you entered will not make a valid triangle.";
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);
	return 0;
}

It is returning a C2064 error at the equation "A=sqrt(s(s-SideB)(s-SideC)(s-SideD))".

If anyone can help please do.

The program is to define the area of a triangle.

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 05 October 2006 - 02:24 AM

First, when posting code, please use the [ code ] [ /code ] tags. I have added them for you for this post.

Second, you should include a description of the error rather than just the code 'C2064' - not everyone uses the Microsoft compiler, and even those who do don't have all the error codes memorized. :)

Finally, as to your actual question, I believe it's that you're trying to multiply by writing s(s-sideB). You can't multiply things by putting them right next to each other in most programming languages, and the compiler error indicates that you're trying to call s as if it were a function, when it's not. Write s * (s - sideB) instead.

Also, I noticed that in the if-statement a few lines below, you have a bunch of conditions separated by commas. That also doesn't do what you think it does. If you were trying to OR those conditions together, use double vertical bars || between each pair, or if you were trying to AND them use a double ampersands &&.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 donBerto

    Senior Member

  • Members
  • PipPipPipPip
  • 369 posts

Posted 05 October 2006 - 02:28 AM

CollegeProginTraining said:

I am having some problems with this program.

#include <iostream>

#include <math.h>

using namespace std;

int main (){

	double A, s, SideB, SideC, SideD;

	cout << "Please enter the value of Side A: ";

	cin >> SideB;

	cout << "Please enter the value of Side B: ";

	cin >> SideC;

	cout << "Please enter the value of Side C: ";

	cin >> SideD;

	s = (SideB + SideC + SideD)/2;

	A = sqrt (s(s-SideB)(s-SideC)(s-SideD));

	cout << "You entered: " << SideB << "Side A + " << SideC << "Side B + " << SideD << " Side C " << A << " = area." << endl;

	if (SideB + SideC > SideD, SideC + SideD > SideB,SideD + SideB > SideC)

		A = sqrt (s(s-SideB)(s-SideC)(s-SideD));

	else

		cout << "The numbers you entered will not make a valid triangle.";

	cout.setf(ios::fixed);

	cout.setf(ios::showpoint);

	cout.precision(2);

	return 0;

}

It is returning a C2064 error at the equation "A=sqrt(s(s-SideB)(s-SideC)(s-SideD))".

If anyone can help please do.

The program is to define the area of a triangle.

if you look closely at your equation, you're missing an operand(?) between s and the expressed enclosed by parenthesis.

hope that helps
Imagine.

#4 CollegeProginTraining

    New Member

  • Members
  • Pip
  • 4 posts

Posted 12 November 2006 - 03:57 AM

Thanks guys,
Yea it worked out. I can't believe it was something small like that.
Thanks for your help nonetheless.
-Brendan





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users