0

I am trying to brush up on C++, which I haven't used in 5 years. I am having problems with the following. Does anyone see the problem in this code? ("sqr(x) is defined in macro.h)

#include "stdafx.h"
#include "macro.h"
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
float a, b, c, result;
char side;

cout<<"For which side are you trying to solve - a, b, or c? \n";
cin>>side;
if (side == 'a')
{
cout << " b = ";
cin >> b;
cout << " c = ";
cin >> c;
cout << endl;

result = sqrt((sqr(c))-(sqr(b)));
cout << "Side a = "<<result<<endl;
}

else if (side == 'b')
{
cout << " a = ";
cin >> a;
cout << " c = ";
cin >> c;
cout << endl;

result = sqrt((sqr(c))-(sqr(a)));
cout << "Side a = "<<result<<endl;
}
else
{
cout << " a = ";
cin>>a;
cout << " b = ";
cin>>b;
cout << endl;

result = sqrt((sqr(a))+(sqr(b)));
cout << "Side b = "<<result<<endl;

}

return 0


__________________
SEO

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by dkalita
0
result = sqrt((sqr(c))-(sqr(b)));

if c>b then u will have sqrt(-ve number).

U cant calculate sqrt for a negative number.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.