Raaaviiii
#include<stdio.h>
#include<math.h>
int distance(int x1,int y1,int x2,int y2);
int point_inside_triangle();
int area_of_triangle(int x1,int y1,int x2,int y2,int x3,int y3);
int main()
{
int x1,y1,x2,y2,x3,y3,x,y,area;
printf("enter the x and y co ordinates of vertex 1: \n");
scanf("%d%d",&x1,&y1);
printf("enter the x and y co ordinates of vertex 2: \n");
scanf("%d%d",&x2,&y2);
printf("enter the x and y co ordinates of vertex 3: \n");
scanf("%d%d",&x3,&y3);
area_of_triangle(x1,y1,x2,y2,x3,y3);
printf("area of triangle is:%d\n",area);
printf("enter the points x,y to check whether they lies inside triangle or not:\n");
scanf("%d%d",&x,&y);
point_inside_triangle(x,y);
if(area_of_triangle(x1,y1,x2,y2,x3,y3)==1)
printf("point lies inside triangle\n");
else
printf("point lies outside triangle\n");
return 0;
}
int distance(int x1,int y1,int x2,int y2)
{
int dist;
dist=sqrt(pow((x2-x1),2)+pow((y2-y1),2));
return (dist);
}
int area_of_triangle(int x1,int y1,int x2,int y2,int x3,int y3)
{
int S1,S2,S3,S,area;
S1=distance(x1,y1,x2,y2);
S2=distance(x1,y1,x3,y3);
S3=distance(x2,y2,x3,y3);
S=(S1+S2+S3)/2;
area=sqrt(S*(S-S1)*(S-S2)*(S-S3));
return (area);
}
int point_inside_triangle(int x,int y,int x1, int y1, int x2, int y2, int x3, int y3,int area)
{
int A1,A2,A3,A;
A1=area_of_triangle(x1,y1,x2,y2,x,y);
A2=area_of_triangle(x1,y1,x3,y3,x,y);
A3=area_of_triangle(x3,y3,x2,y2,x,y );
A=A1+A2+A3;
if(A==area)
return 1;
else
return 0;
}
can anyone tell me what is the mistake in this code please??
Anonymous
Sorry guys!
Someone to help me with this one,,,,,
#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;
int loggedin()
{
string password,username,pass,us;
cout<<"enter password :\n";
cin>>password;
cout<<"enter username :\n";
cin>>username;
ifstream read;
read.open("database.txt");
if(read.fail());
getline(read,us);
getline(read,pass);
read.close();
if(us==username && pass==password)
{
return 1;
}
else
{
return 0;
}
}
int main ()
{ int choice;
cout<<"1 register :\n";
cout<<"2 loggin :\n";
cout<<"3 exit :\n";
cout<<"enter your choice :\n";
cin>>choice;
if(choice==1)
{
string us,pass;
cout<<"enter username :\n";
cin>>us;
cout<<"enter password :\n";
cin>>pass;
ofstream file;
file.open("database.txt");
file<<us; cout<<endl; file<<pass;
file.close();
main();
}
else if(choice==2)
{
bool m= loggedin();
if(m!=1)
{
cout<<"wrong input\n";
main();
return 0;
}
else
{
cout<<"loggin successfully\n";
main();
return 1;
}
}
}
Even when the username and password are correct the program keeps saying "wrong input"