Guys I have a logic error in my code and I cant seem to spot it!this program should calculate the circumference of a circle or the perimeter of a rectangle by using overloaded functions. My calculations yield correct answers but yet i dont seem to be getting the if and else clause right. Please advise as the program must only do either the circumference or the perimeter not both. Mine executes both.
#include <iostream>
#include <iomanip>
using namespace std;
// This program calculates the perimeter of a rectangle and the circumference of a circle depending on what calculation the user has selected.
double calcCircumference (double radius)
{
double PI = 3.14285; double circumference;
cout << "Enter radius of the circle: " << endl;
cin >> radius;
circumference = 2 * PI * radius;
cout << "The circumference of the circle is: " << circumference <<endl;
'C' in a context where a value of type bool is expected is always true, since it is non-zero.
So your first condition was eqivalent to: (entered =='c' || true) && (entered != 'p' || true)