Fixed Pathagorean Theorm Thanks!

#include <iostream>
#include <math.h>
#include <string>

using namespace std;

int main()

{


cout << "What value would you like to solve for a, b, or c?";

float sideA, sideB, sideC;
char a, b, c;
char choice;

cin >> choice;



if (choice=='a')
//user enters a after the question which side to solve for and when the user does, it will run the if statement below, having the user input b and c.

{
cout << "Input the value of b: ";
cin >> sideB; // input the number of side b
cout << endl;

cout << "Input the value of c: ";
cin >> sideC; // input the number of side c
cout << endl;

sideA = (sideC * sideC) - (sideB * sideB);
sideA = sqrt(sideA);

//solving for side a

cout << "The value of side a is equal to: " << sideA << endl << endl;
//did the <<endl<< endl just for the look of the output.
}



if (choice=='b')
//user enters b after the question which side to solve for and when the user does, it will run the if statement below, having the user input a and c.


{
cin.ignore();
cout << "Input the value of a: ";
cin >> sideA; //Input of side a
cout << endl;

cout << "Input the value of c: ";
cin >> sideC; //Input of side c
cout << endl;

sideB = (sideC * sideC) - (sideA * sideA);
sideB = sqrt(sideB);

//solving for side b

cout << "The value of side b is equal to: " << sideB << endl << endl;

}




if (choice=='c')
//user enters c after the question which side to solve for and when the user does, it will run the if statement below, having the user input a and b.


{
cin.ignore();
cout << "Input the calue of a: ";
cin >> sideA; //Input of side a
cout << endl;

cout << "Input the value of b: ";
cin >> sideB; //Input of side b
cout << endl;

sideC = (sideA * sideA) + (sideB * sideB);
sideC = sqrt(sideC);

//solving for side c
cout << "The value of side c is equal to: " << sideC << endl << endl;
}

}
Last edited on
I think you misunderstand what "cin >> a" means, it doesn't mean that the user has input "a" but asks the user to input a value that will be stored in a.

What you want to do is store user input in a char then check what the value of that is.
For example, something along the lines of this would work:
1
2
3
4
5
6
7
char input;
cin >> input;
if(input == 'a')
{
     run code...
}
else ...


Also, please use the code tags around your code to make it easy to view.
Last edited on
I think you could do this
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include <math.h>
#include <string>

using namespace std;

int main()

{


cout << "What value would you like to solve for a, b, or c?";

float sideA, sideB, sideC;
char a, b, c;
char choice;

cin >> choice;



if (choice=='a') 
//user enters a after the question which side to solve for and when the user does, it will run the if statement below, having the user input b and c.

{
cout << "Input the value of b: ";
cin >> sideB; // input the number of side b
cout << endl;

cout << "Input the value of c: ";
cin >> sideC; // input the number of side c
cout << endl;

sideA = (sideC * sideC) - (sideB * sideB);
sideA = sqrt(sideA);

//solving for side a

cout << "The value of side a is equal to: " << sideA << endl << endl;
//did the <<endl<< endl just for the look of the output.
}



if (choice=='b') 
//user enters b after the question which side to solve for and when the user does, it will run the if statement below, having the user input a and c.


{
cin.ignore(); 
cout << "Input the value of a: ";
cin >> sideA; //Input of side a
cout << endl;

cout << "Input the value of c: ";
cin >> sideC; //Input of side c
cout << endl;

sideB = (sideC * sideC) - (sideA * sideA);
sideB = sqrt(sideB);

//solving for side b

cout << "The value of side b is equal to: " << sideB << endl << endl;

}




if (choice=='c')
//user enters c after the question which side to solve for and when the user does, it will run the if statement below, having the user input a and b.


{
cin.ignore();
cout << "Input the calue of a: ";
cin >> sideA; //Input of side a
cout << endl;

cout << "Input the value of b: ";
cin >> sideB; //Input of side b
cout << endl;

sideC = (sideA * sideA) + (sideB * sideB);
sideC = sqrt(sideC);

//solving for side c
cout << "The value of side c is equal to: " << sideC << endl << endl;
}

}
Last edited on
Thanks for all the help! I knew i just needed something simple to add, but just couldn't figure out what I needed. Thanks again!
Topic archived. No new replies allowed.