+ 1

function calling inside if condition

#include <iostream> using namespace std; class Box { public: // Constructor definition Box(double l = 2.0, double b = 2.0, double h = 2.0) { cout <<"Constructor called." << endl; length = l; breadth = b; height = h; } double Volume() { return length * breadth * height; } int compare(Box box1) { Box temp; if(temp.Volume()>box1.Volume()) ///*** if(temp.Volume();>box1.Volume();)//with semicolon its not working why ??? { return 1; } else return 0; } private: double length; // Length of a box double breadth; // Breadth of a box double height; // Height of a box }; int main(void) { Box Box1(3.3, 1.2, 1.5); // Declare box1 Box Box2(8.5, 6.0, 2.0); // Declare box2 if(Box1.compare(Box2)) { cout << "Box2 is smaller than Box1" <<endl; } else { cout << "Box2 is equal to or larger than Box1" <<endl; } return 0; }

15th Jul 2018, 9:08 AM
Siddharth Jain
Siddharth Jain - avatar
3 Respostas
0
If "statement" get an "expression" like condition Read here http://www.informit.com/articles/article.aspx?p=2472079&seqNum=4
15th Jul 2018, 9:32 AM
KrOW
KrOW - avatar
+ 1
Because semicolon its not allowed here P.S. Post your not-short code like link to save code in 'Code Playground' section
15th Jul 2018, 9:10 AM
KrOW
KrOW - avatar
+ 1
KrOW in fuction calling we have to put semicolon at the end
15th Jul 2018, 9:12 AM
Siddharth Jain
Siddharth Jain - avatar