2 Replies - 1374 Views - Last Post: 16 February 2010 - 09:51 PM Rate Topic: -----

#1 vonnie15  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 16-February 10

's' can not be used as a function

Posted 16 February 2010 - 09:31 PM

I have an error that states
's' can not be used as a function

here is my code

// Isak Ivanic
// 2/16/10
// CSC 150, 2:00 pm
// Program 3 Part 1
// This program calculates the total area as well as perimeter of a triangle
#include <iostream>
#include <iomanip>             // For setpercision
#include <cmath>               // For the sqrt function
using namespace std;

void welcome ();               // Welcome function

int main ()

{
    welcome();                      // Function call
    double lengthA,                 // To hold the length of side A
          lengthB,                  // To hold the length of side B
          lengthC,                  // To hold the length of side C
          A,                        // To hold the area formula
          s;                        // To hold the perimeter formula
          
     // Calculate the perimemter and area of the triangle
    cout << "The length of side A is: ";
    cin >> lengthA;
    cout << "The length of side B is: ";
    cin >> lengthB;
    cout << "The length of side C is: ";
    cin >> lengthC;
    s=(lengthA + lengthB + lengthC)/2;
    
    //Display the perimeter
    cout << "The perimeter of the triangle is:" << s;
    
    //Calculate the area of the triangle
    A=sqrt(s(s-lengthA)(s-lengthB)(s-lengthC));
    
    //Display the area of the triangle
    cout << setprecision(1) << "The area of the triangle is: " << A << endl;
    
    system ("Pause");
    
    return 0;
} 

// Function definition
void welcome ()
{
     cout << "*************************************\n";
     cout << "* Welcom to the best program ever! *\n";
     cout << "**************************************\n";
}
   






The Error takes place here


  //Calculate the area of the triangle
    A=sqrt(s(s-lengthA)(s-lengthB)(s-lengthC));




please help....

Is This A Good Question/Topic? 0
  • +

Replies To: 's' can not be used as a function

#2 anonymouscodder  Icon User is offline

  • member icon

Reputation: 126
  • View blog
  • Posts: 710
  • Joined: 01-January 10

Re: 's' can not be used as a function

Posted 16 February 2010 - 09:41 PM

A=sqrt(s(s-lengthA)(s-lengthB)(s-lengthC));
In C/C++ there is no implicit multiplication as in math..

So if your idea was to perform a multiplication, the correct would be:
A=sqrt(s*(s-lengthA)*(s-lengthB)*(s-lengthC));

Was This Post Helpful? 1
  • +
  • -

#3 vonnie15  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 16-February 10

Re: 's' can not be used as a function

Posted 16 February 2010 - 09:51 PM

View Postanonymouscodder, on 16 February 2010 - 08:41 PM, said:

A=sqrt(s(s-lengthA)(s-lengthB)(s-lengthC));
In C/C++ there is no implicit multiplication as in math..

So if your idea was to perform a multiplication, the correct would be:
A=sqrt(s*(s-lengthA)*(s-lengthB)*(s-lengthC));


Thank you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1