OK so i am writing this program for the pythagorean Theorem and i got everything together and went to compile it, but i keep many errors and i cant figure out what im doing wrong
Here is the program:
#include <iostream>
#include <cmath>
#include <cstdlib>
usingnamespace std;
int main()
{
int leg1;
int leg2;
int H;
int ans;
int choice;
cout<< "Pick option 1 or 2: 1. Leg is missing 2.Hypotenuse is missing"<< endl;
cin>> choice >> endl;
switch(choice)
{
Case 1:
cout<< "Enter values of leg and hypotenuse:";
cin >> leg1 >> H >> endl;
(H*H) - (leg1*leg1) = ans;
ans = sqrt(ans);
cout << "The missing leg is: " <<ans;
break;
Case 2:
cout << "Enter value of both legs: ";
cin>> leg1 >> leg2 >> endl;
ans = (leg1*leg1) + (leg2*leg2);
ans = sqrt(ans);
cout << "The hypotenuse is " << ans;
break;
default:
cout <<"Must enter a 1 or 2";
}
system("Pause")
return 0;
}
Line 24 should be written as ans = (H*H) - (leg1*leg1);.
Lines 20 and 31: Keywords in C++ are case-sensitive. Use case.
#include <iostream>
#include <cmath>
#include <cstdlib>
usingnamespace std;
int main()
{
int leg1;
int leg2;
int H;
int ans;
int choice;
int y=1;
int n=0;
char response;
do
{
cout<< "Pick option 1 or 2:" << endl << "1. Leg is missing 2.Hypotenuse is missing"<< endl;
cin>> choice;
switch(choice)
{
case 1:
cout<< "Enter values of leg:";
cin >> leg1;
cout << "Enter value of hypotenuse:";
cin >> H;
ans = (H*H) - (leg1*leg1);
ans = sqrt(ans);
cout << "The missing leg is: " << ans << endl;
break;
case 2:
cout << "Enter value of one leg: " << endl;
cin>> leg1;
cout << "Enter value of other leg:" << endl;
cin >> leg2;
ans = (leg1*leg1) + (leg2*leg2);
ans = sqrt(ans);
cout << "The hypotenuse is " << ans << endl;
break;
default:
cout <<"Must enter a 1 or 2";
}
cout << "Would you like to try for another right triangle? (y/n)" << endl;
cin >> response;
system("CLS");
}
while (response == 'y');
system("Pause");
return 0;
}
When i run, it in the beginning when i dont press a one or two it goes to default and then it will also run the want to try again part. How do i get it to not run the try again part when it goes to default but instead run one that says something like retry because i want them to press a one or two
Works fine for me. Only thing I see wrong now is that you declare int y and n but don't use them. Otherwise it compiled fine and ran using Code::Blocks and GCC compiler 4.7.2
well what i want to happen is that i want the try for another triangle to apply to only case1 and 2 but not happen at default. At default i want it to just retart