square root

#include <iostream>
#include <cmath>
#include <stdio.h>
#include <math.h>


using namespace std;

int main()
{
int choice1, choice2, choice3, sqrt, intercept;
double M, area_triangle, y, x, M1;
float x1, x2, x3, y1, y2, y3, x4, y4, x5, y5, m1,m2, c1, a1,b1, a, b, c, m;

cout<< "**********************************************************"<<endl;
cout<< " This is a Program for calculating solid geometric according to its formula"<<endl;
cout<< "***********************************************************"<<endl;

cout <<endl;
cout<<endl;

cout<<" Please select an option that you want to calculate: "<<endl;
cout<<"1. Distance and gradient"<<endl;
cout<<"2. Midpoint"<<endl;
cout<<"3. Area of Triangle"<<endl;
cout<<"4. Equation of straight line"<<endl;

cout<<endl;
cin>>choice1;

cout<<endl;
cout<<endl;

switch (choice1)
{
case 1:
cout <<"1. Distance in triangle"<<endl;
cout<< "2. Gradient of line"<<endl;
cout<< "3. Parallel"<<endl;
cin>>choice2;

if (choice2==1)
{
cout<< "Please enter 2 coordinate. The value of x1,x2,y1,y2"<<endl;
cin>>x1>>x2>>y1>>y2;

M1 = sqrt((x1-x2) +(y1-y2));
cout << "the distance between the two points are:" << M1 <<endl;

}
else if (choice2==2)
{
cout<< "Please enter the value of x1,x2,y1,y2"<<endl;
cin>>x1>>x2>>y1>>y2;

m = (y2-y1)/(x2-x1);

cout << "the gradient are :" << m << endl;
}
else (choice2==3);
{
cout<< "please enter the value of x1,x2,y1,y2"<<endl;
cin>>x1>>x2>>y1>>y2;
cout << "please enter the other coordinate, (x1,y1),(x2,y2)"<<endl;
cin >> x4>>y4>>x5>>y5;
m1 = (y2-y1)/(x2-x1);
m2 = (y5-y4)/ (x5-x4);
m=m1= m2;

cout<< "the gradient are : "<< m <<endl;
}
break;

case 2:
{
cout<< "to calculate the midpoint of line"<<endl;
cout<< "please enter the value of x1,x2,y1,y2"<<endl;
cin>> x1>>x2>>y1>>y2;

M = (((x1+x2)/2), ((y1+y2)/2));

cout << "the Midpoint between the two lines are : " << M << endl;
}

break;

case 3:
{
cout <<"to calculate the area of triangle"<<endl;
cout <<"please enter the 3 coordinate"<<endl;
cin>>x1>>x2>>x3>>y1>>y2>>y3;

area_triangle= (1/2)*((x1*y2+x2*y3+x3*y1)-(x2*y1+x3*y2+x1*y3));
}
break;

case 4:

cout <<"1. equation in general form"<<endl;
cout <<"2. in linear equation"<<endl;
cout <<"intercept form"<<endl;
cin>>choice3;
{
if (choice3=1)
{
cout << "please enter the value of constant"<<endl;
cin>> a>>b>>c;

cout <<a<<"x"<<"+"<<b<<"x"<<"+"<<c;
}
else if (choice3=2)
{
cout <<"Please enter the value of gradient and constant c"<<endl;
cin>>m1>>c1;

cout << "Y="<<m1<<"x"<<"+"<<c1;
}
else
{
cout << "This formula is Ax+Bx+c."<<endl;
cin>>a1>>b1>>c1;

intercept=(x/a)+(y/b);


}
}
break;

}
return 0;
}


this is my coding for my simple program. the problem is, the squareroot inside the equation. when i try to run the program, it shows error where it says, sqrt cannot be used as a function. what am i supposed to do with it? is there is any solution because the calculation need square root.
thanks for helping. :)
First, this should go to "Begginers" tab.
Secondly, you made "sqrt" integer. There is a name collision.
Change its name to something else_like m_sqrt, int_sqrt, or anything else. And remember that name identifiers should be unique.

Cheers!

PS. This could also be avoided if instead of using
 
using namespace std;

you put std::before every std's function/object.
Last edited on
Do not include <math.h> as it is obsolete. You also don't need <stdio.h>. Also: Please put code in code tags in future!
1
2
3
[code] <-- Put on of these in your post.
std::cout << "Code goes here."; 
[/ code] <-- And a closing one (without the space) 


Last edited on
Topic archived. No new replies allowed.