rasing variable to 2nd power

Say you have variables A B C, that the user puts in a side of a triangle. Obviously I am attempting to make a program that checks to see if a2+b2=c2 is true. The question is, how do I raise the variable to the second power?
Im using Dev C++
Last edited on
You do know what that means, right?

1
2
int a = 10;
int a_squared = a * a;
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
56
57
58
59
60
61
62
#include<iostream>
#include<math.h>
#include <stdlib.h>

using namespace std;

void Start;
void GetResults();

char a, b, c;

void
Start()
{
       while((a * a) + (b * b) != (c * c))
       {
                
                cout << "Please put in line A\n";
                a = 0;
                cin >> a;
                
                cout << "please put in line B\n";
                b = 0;
                cin >> b;
                
                cout << "please put in line C\n";
                c = 0;
                cin << c;
                
                                
                if((a * a) + (b * b) != (c * c))
                {
                      cout << "This is not a Right Triangle.\n";
                }
       }
       
       GetResults();

                if((a * a) + (b * b) == (c * c))
                {
                      cout << "This is a Right Triangle.\n";
                }
}

void 
GetResults();
{
  
             
}

int

main();
{
       a = 0;
       b = 0;
       c = 0;
       cout << "Finds Right Triangles!!!!!\n";
       Start();
       return 0;
}


This what i have so far but it wont compile, it comes with this message Circular main <-Main.o dependency dropped...
I dont even know if this would be remotely the right way to write this program
Start by removing the semicolon on lines 46 and 54.

You're doing fine with the program, it just needs a little refinement.
Last edited on
void Start;

this line should be

void Start();
Last edited on
There is something
c=0;
cin << c;
This should be
c=0;
cin >>c;
Thank you for The catches, but it didnt fix my problem. I dont know how to fix it!!!!
Last edited on
You need to make sure that variable c is the hypotenuse of the right triangle. (That's the longest side of the triangle.) To do this, make a variable called temp of the same type as a, b, and c. Then after you input a, b, and c, use code like this:

1
2
3
4
5
6
7
8
9
10
if (a > c) {
  temp = a;
  a = c;
  c = temp;
}
if (b > c) {
  temp = b;
  b = c;
  c = temp;
}


Also, you should use a do-while loop with this code, not a while loop.

~psault
Topic archived. No new replies allowed.