-
bool functions
if i am using a bool function such as
Code:
bool isaMonkey(*)
int main ()
{
cout << isaMonkey(*) << endl;
returno
;
//
function parameters to determine isaMonkey...
furry skin, curly tail, eats bananas....
what is listed at ther astericks? true, false, both? The paramerters?
i am being told that my isaMonkey term doesn't evaluate to a function..
Thanks scuba22 (michele)
ps
isaMonkey is justanexample....but the question is a yes or no, which is why I am using bool.
Thx
-
A function that returns bool is just like any other function. You pass it arguments and if those arguments evaluate to true you return true, otherwise false:
Code:
#include <iostream>
bool isGreater ( int one, int two )
{
return one > two;
}
int main()
{
int i = 27, j = 15;
std::cout<< isGreater ( j, i ) <<std::endl;
std::cout<< isGreater ( i, j ) <<std::endl;
return 0;
}
-Prelude
-
Code:
bool IsAMonkey(bool FurrySkin,bool CurlyTail,bool EatsBananas)
{
return (FurrySkin && CurlyTail && EatsBananas) ? true:false;
}
something like that?
IsAMonkey(true,true,true) returns true. Anything else returns false. So only a monkey if has furry skin and curly tail and eats bananas.
-
thank you
thanks * thanks * thanks * for the quick reply
scuba22
-
more probs with this...
actually my boolquestion is : isatriangle
so the sum of 2 sides must be greater than the third to be true
here's my fuction prototype:
Code:
bool isatriangle (double, double, double);
i start my main and get my data (numbers for 3 sides)
call my function:
Code:
cout<<setw(15) << s1 << s2 << s3 <<setw(15)<<isatriangle(s1, s2, s3)
and here's my function:
Code:
//function isatriangle definition
//x,y,z are parameters
bool isatrianle( double x, double y, double z){
bool iat = false;
if (y + z > x)
iat = true;
if (x + z > y)
iat = true;
if (x + y > z)
iat = true;
return iat;
}
but something is wrong and i'm getting this error:
unresolved external symbol "bool __cdecl isatriangle(double,double,double)" (?isatriangle@@YA_NNNN@Z)
Debug/HW_1018.exe : fatal error LNK1120: 1 unresolved externals
can you point out what's wrong?
scuba22
-
You misspelled the function name in your definition.
-Prelude
-
more?
okay..thanks...duh.
one last question...
here's the new prototype & fuction,
why am I not getting a yes or no when i call the bool function?
actually what the hey..here's the entire thing...my output is a little messed up...
Code:
#include<iostream>
#include<iomanip>
#include<fstream>
#include<cmath>
#include<string>
using namespace std;
bool isatriangle (double, double, double);
double semiperimeter ( double, double, double );
double perimeter ( double, double, double );
double area ( double, double, double );
int main()
{
double s1, s2, s3;
ifstream infile("A:\\IF1.txt");
if(!infile){
cerr << "Cannot open input file" << endl;
return 1;
}
ofstream outfile("A:\\0F1.txt");
if(!outfile){
cerr << "Cannot open output file" << endl;
return 1;
}
cout << setprecision(3);
cout << setiosflags(ios::fixed | ios::showpoint);
cout << "\n" << endl;
bool Flag = true;
while(infile >> s1 >> s2 >> s3){
if(Flag==true){
cout<<setw(15)<<"\tSIDES"<<setw(15)<<"TRIANGLE ?"<<setw(15)<<"PERIMETER"<<setw(15)<<"AREA\n" << endl;
Flag=false;
}
cout<<setw(15) << s1 << s2 << s3 <<setw(20)<<isatriangle(s1, s2, s3)<<setw(20)<<perimeter( s1, s2, s3 )<<setw(20)<< area(s1, s2, s3)<<"\n\n" <<endl;
}
return 0;
}
//function isatriangle definition
//x,y,z are parameters
bool isatriangle( double x, double y, double z){
return ((y + z > x) && (x + z > y) && (x + y > z)) ? true:false;
}
//function perimeter definition
// a,b,c are parameters
double perimeter ( double a, double b, double c ){
cout << setprecision(3);
cout << setiosflags(ios::fixed | ios::showpoint);
double p = (a + b + c);
return p;
}
//function semiperimeter definition
// a,b,c are parameters
double semiperimeter ( double a, double b, double c ){
double sp = (a + b + c )/2;
return sp;
}
//function area definition
// a,b,c, and are parameters
double area ( double a, double b, double c ){
cout << setprecision(3);
cout << setiosflags(ios::fixed | ios::showpoint);
double sp;
double B = sp * (sp-a)*(sp-b)*(sp-c);
double A = sqrt(B);
return A;
}
-
1 or 0
i'm getting 1 or zero for my bool answer of true or false...
also, I am trying to get the area to call the semiperimeter fuction for calculation, but am not getting asnything back..am I doing it wrong?
Michele
-
1 or 0
hey all never mind..i've figured it out thanks...
working on one function calling another.
thanks for your help bonkey, prelude, and 'coned stoder'
scuba22