Calculating 3rd side of right triangle

Hi, I am extremely new to c++ this is my first language ever and I need some help
That is what I have but I get an error c2661 'pow' no overload function takes 1 arguments. It is down in sideC = sqrt[(pow(sideOne) + pow(sideTwo))]; What is wrong?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<iostream>
#include<cmath>
using namespace std;

float getSideOne();
float getSideTwo();
float calcSideC(float sideOne, float sideTwo);
void showSideC (float sideC);



int main()
{
	float sideOne;
	float sideTwo;
	float sideC;

	sideOne = getSideOne();
	sideTwo = getSideTwo();
	sideC = calcSideC(sideOne, sideTwo);
	showSideC(sideC);
	
	
	
	
	return 0;
}

float getSideOne()
{
	float sideOne;
	cout << "Enter the length of the first side\n";
	cin >> sideOne;
	return sideOne;
}

float getSideTwo()
{
	float sideTwo;
		cout << "Enter the length of the second side\n";
		cin >> sideTwo;
		return sideTwo;
}

float calcSideC(float sideOne, float sideTwo)
{
	float sideC;
	sideC = sqrt[(pow(sideOne) + pow(sideTwo))];
	return sideC;
}

void showSideC(float sideC)
{
	cout << "Side C is equal to "<< sideC << "";
}
I think your problem lies here sideC = sqrt[(pow(sideOne) + pow(sideTwo))];

Try replacing those brackets with parenthesis.
Parasin, I still get the same error when I do that


documents\visual studio 2010\projects\hw_7a\hw_7a\hw_7a.cpp(56): error C2661: 'pow' : no overloaded function takes 1 arguments
pow takes two parameters, not one. You want to raise sideOne to some power (in this case, presumably using the pythagorean theorem, 2):
pow(sideOne, 2) Same goes for sideTwo. In general, pow(x, y) returns x to the yth power. Also, is there any reason you're using single-precision float instead of declaring your variables as double?

http://www.cplusplus.com/reference/cmath/pow/
Last edited on
 
sideC = sqrt((pow(sideOne,2) + pow(sideTwo,2)));


Update with this line in your calcSideC () function
Thank you so much! I haven't used a pow() function in a while so I sort of forgot. I was thinking of using double first but I didn't know which would be better

I am 18 and this is my first programming class ever. Is it okay to struggle? I feel so stupid sometimes.
I'm new to programming as well mate and it is difficult as you need to adjust the way you think about problems and in addition you are learning a new language.

I personally think you have your programme properly formatted, which many beginners don't.

Thanks RabMac, my teacher focuses heavy on good coding style. I am taking intro to c++ programming at a CC right now. We go faster than all the other CCs in the area and other areas I believe for this class. Most intro to c++ classes finish at learning to write to/read a file, we do that about the 4th or 5th week so double the pace. It gets overwhelming but I love it. Wish I was amazing at it though
The compile issue may be resolved, but the use of the pow() function here is somewhat of a sledgehammer to crack a walnut. Internally it will probably get the log, multiply by the power and then get the antilog, when all that is required is to multiply a number by itself.
What would you have recommended, Chervil?
Well, this would have been my preference:
 
    sideC = sqrt(sideOne*sideOne + sideTwo*sideTwo);

Though as I say, its a preference rather than right or wrong.
Topic archived. No new replies allowed.