### 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:
 ``1234567`` ``````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
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192`` ``````#include #include #include 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 <> 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.