Displays Question Twice

So I am writing a program that can calculate the sin law for me, and i have written quite a few programs using the goto Redo; command, but I have never had it display my question twice. After I solve for one of the variables I just want it to go back to the main question, which variable I want to solve for.
My problem is that it displays the question twice, the first time it doesnt even give me a chance to type any input, than right below it, it displays the question again and this time it allows me to type something in.
How do I get rid of that first dud question?


#include <iostream.h>
#include <math.h>
#define NEWLINE '\n'
#define PI 3.14159265
using namespace std;

int main()
{
cout << " x y " << NEWLINE;
cout << " ----- = ----- " << NEWLINE;
cout << " sin(X) sin(Y) " << NEWLINE;
cout << NEWLINE << NEWLINE << NEWLINE;


Redo :

{
string input;
cout << NEWLINE << NEWLINE << NEWLINE;
cout << "Please Enter the Variable You Wish to Solve For : ";
getline(cin, input);
cout << NEWLINE << " ---------------------------------------------- " << NEWLINE;

if (input == "x")
{
double x, y, X, Y, A, B;
cout << "y = ";
cin >> y;
cout << NEWLINE << NEWLINE;

cout << "sin(X) = ";
cin >> X;
cout << NEWLINE << NEWLINE;

cout << "sin(Y) = ";
cin >> Y;
cout << NEWLINE << NEWLINE;

A = Y*(PI/180);
B = X*(PI/180);
x = (y*sin(B)/sin(A));

cout << "x = " << x;


}

else if (input == "y")
{
double A, B, X, Y, x, y;
cout << "x = ";
cin >> x;
cout << NEWLINE << NEWLINE;

cout << "sin(Y) = ";
cin >> Y;
cout << NEWLINE << NEWLINE;

cout << "sin(X) = ";
cin >> X;
cout << NEWLINE << NEWLINE;

A = Y*(PI/180);
B = X*(PI/180);
y = (x*sin(A)/sin(B));

cout << "y = " << y;


}

else if (input == "Sin(X)" || input == "sin(X)" || input == "SIN(X)" || input == "sin(x)")
{
double x, y, X, Y, A, B, C;
cout << "x = ";
cin >> x;
cout << NEWLINE << NEWLINE;

cout << "y = ";
cin >> y;
cout << NEWLINE << NEWLINE;

cout << "sin(Y) = ";
cin >> Y;
cout << NEWLINE << NEWLINE;

A = Y*(PI/180);
B = (x*sin(A)/y);
X = asin(B);
C = X*(180/PI);

cout << "Sin(X) = " << C;

}

else if (input == "Sin(Y)" || input == "sin(Y)" || input == "SIN(Y)" || input == "sin(x)")
{
double A, B, x, y, X, Y, C;
cout << "x = ";
cin >> x;
cout << NEWLINE << NEWLINE;

cout << "y = ";
cin >> y;
cout << NEWLINE << NEWLINE;

cout << "sin(X) = ";
cin >> X;
cout << NEWLINE << NEWLINE;

A = X*(PI/180);
B = (y*sin(A)/x);
Y = asin(B);
C = Y*(180/PI);

cout << "sin(Y) = " << C;
}


}
goto Redo;
return 0;

}
You use getline and cin >> together which causes the problem.

You could replace getline(cin, input); with cin>>input;


or look up how to ignore the rest of the characters in the cin stream and place the command after all the elseif clauses.
Last edited on
Topic archived. No new replies allowed.