/*This program is to help you figureout the Sine of a triangle. It
uses division to find a result.*/
#include <iostream>
int main()
{
using std::cout;
using std::cin;
using std::endl;
cout << "\n";
cout << " Imagine you have a Right Triangle and you want to find the Sine.\n";
cout << "First you would need to label all of the angles. Lets say the Right\n";
cout << "angle is A, the acute angle is B(Your Sine angle), and the last\n";
cout << "angle is C. Sine = measure of the leg opposite angle B / measure of\n";
cout << "the hypotenuse.\n";
unsignedshort MeasureOfLegOpposite;
float MeasureOfTheHypotenuse;
unsignedshort Sine = (MeasureOfLegOpposite / MeasureOfTheHypotenuse);
cout << "\nWhat is the measure of the leg opposite your angle? ";
cin >> MeasureOfLegOpposite;
cout << "\nAnd what is the measure of the hypotenuse? ";
cin >> MeasureOfTheHypotenuse;
cout << "\n";
cout << "So the Sine of angle B is: ";
cout << Sine;
cout << "\n\n";
cout << "Thanks!";
int exit;
cin >> exit;
return 0;
}
When I type in my numbers it never works. Its just says the samething every time. The division worked when I substituted the cin >> with pre set numbers. Thats whats confussing.
Yes, your sine variable isn't dynamic, it's static meaning that when you create it it's set to what the values you are dividing are at the time. It won't work like that, so move it to after you're finished calculating, personally I think it makes more sense to do it like this:
/*This program is to help you figureout the Sine of a triangle. It
uses division to find a result.*/
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
unsignedshort MeasureOfLegOpposite = 0, Sine = 0;
float MeasureOfTheHypotenuse = 0.0;
cout << "\n";
cout << " Imagine you have a Right Triangle and you want to find the Sine.\n";
cout << "First you would need to label all of the angles. Lets say the Right\n";
cout << "angle is A, the acute angle is B(Your Sine angle), and the last\n";
cout << "angle is C. Sine = measure of the leg opposite angle B / measure of\n";
cout << "the hypotenuse.\n";
cout << "\nWhat is the measure of the leg opposite your angle? ";
cin >> MeasureOfLegOpposite;
cout << "\nAnd what is the measure of the hypotenuse? ";
cin >> MeasureOfTheHypotenuse;
cout << "\n";
Sine = (MeasureOfLegOpposite / MeasureOfTheHypotenuse); // Assign the value to sign
cout << "So the Sine of angle B is: " << Sine << "\n\nThanks!";
cin.get(); // You don't need to use cin, cin.get() will read until newline/return/enter is pressed
return 0;
}