Call of nonfunction error: what should fix this?

Ok.
I have an assignment to take an algorithm, and write the code for it. I am a freshman in college and a beginner at C++. Please excuse the small, common mistakes.

Here is the information given:
A, B, and C denote the lengths of a side of a triangle. The area is calculated by the following formula: square root of (s(s-A)(s-B)(s-C))
s = (1/2)(A+B+C)

Here is my code that I have written so far:

#include <iostream>
#include <cmath>

using namespace std;

float A;
float B;
float C;
float s;

int main ()
{
cout << "Please insert the values for A, B, and C, ";
cout << "each separated by a space." << endl;
cin >> A >> B >> C;
cout << endl;

s = (1/2)(A+B+C);

cout << "The area of the triangle is ";
cout << sqrt(s(s-A)(s-B)(s-C)) << endl;
cout << ".";

return 0;
}

The error I keep receiving when I try to compile this code says:
Error E2314 P22mtb.cpp 19: Call of nonfunction in function main()
Error E2314 P22mtb.cpp 22: Call of nonfunction in function main()

What is wrong? Please enlighten me with whatever useful information you may have. I greatly appreciate everyone that helps out.
Thank You.
In C++, (1)(1) is not multiplication, as it is in algebra. Try (1)*(1). Lines 18 and 21 both need fixed (line numbers are based on #include <iostream> being line 1).
Last edited on
Wow.... you can tell I'm new at this. I knew that it wasn't the same as algebra but, being a newbie, completely didn't even notice it. It compiles perfectly now, but it is not giving the correct answer. Will the placement of
s = (1/2)*(A+B+C);
have anything to do with the output?
Thank you once again.
Ah, I didn't even notice... Here's the deal: 1/2 is integral division. Try 1/2.0 so that the compiler knows to use floating point arithmetic.
That worked perfectly! Thank you for your assistance. I have a feeling that I have A LOT to learn about C++. Any words of wisdom for my future programming endeavors?
Glad to help out.

My advice is to read a lot. You can only progress so fast on your own; books can speed up the process tremendously. Years of experience and wisdom can be simply handed down to you in even a short book.
Years of experience and wisdom can be simply handed down to you in even a short book.


Strangely, I was going to say almost the opposite. XD

Books can teach you the rules and the syntax, but there's no substitute for your own experience. The only way to learn C++ is to write programs with it.
moorecm
Unfortunately, personally, I'm going to have to agree with Disch on this one. I know books hold LOADS of information, but I am the type of person that people would say is not a reader. With what I've learned so far, I have learned it by doing it. I've tried to read through the book along with the class, but I just don' seem to hold the information like everyone else. Thank you both for your recommendations. I'm sure I'll have more questions to come, but there's nothing I won't be able to accomplish (especially with the help from the members of cplusplus.com). :D
Topic archived. No new replies allowed.