Calculator problem

i run this,and on line 34, the if statement runs and works, but after "Enter the operation you wanna perform: " it doesn't wait for input, and it skips the rest of the program and exits. thanks for any help.

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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
  #include <iostream>
#include <Windows.h>
#include <cstdlib>
#include <cmath>
#include <string>
using namespace std;

double add(double &d, double &e);
double subtr(double &d, double &e);
double multip(double &d, double &e);
double divi(double &d, double &e);
double radical(double &d);
double square(double &d);

int main()
{


	HANDLE hConsole;
	hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN| FOREGROUND_INTENSITY);




	double d(0), e(0), f(0);
	double g(0), h(0), i(0);
	string first;
	string ans;
	cout << "Enter the number you want to use: ";
	cin >> d;
	cout << "need another number? (y/n): ";
	cin >> ans;
	if (ans == "y")
	{
		cout << "Enter your second number: ";
		cin >> e;
		cout << "Enter the operation you wanna perform: ";
			getline(cin, first);
	}
	else
	{
		cout << "Enter the operation you wanna perform: ";
		getline(cin, first);
	}
	
	
	//input handling-------------------------------------------------------------------------------------------------------------------------------------------
	
	if (first == "add" || first=="addition"||first=="Add"||first=="Addition"||first=="ADD"||first=="ADDITION")
	{
		system("cls");
		cout<<add(d,e);
	}
	
	else if (first == "subtract" || first == "subtraction" || first == "Subtract" || first =="Subtraction" || first =="SUBTRACT"||first=="SUBTRACTION")
	{
		system("cls");
		cout<<subtr(d,e);
	}

	
	else if (first == "multiply" || first == "multiplication" || first == "Multiply" || first =="Multiplication" || first =="MULTIPLY"||first=="MULTIPLICATION" )
	{
		system("cls");
		cout << multip(d,e);
	}

	
	else if (first == "divide" || first == "division" || first == "Divide" || first == "Division" || first == "DIVIDE" || first == "DIVISION")
	{
		system("cls");
		cout << divi(d,e);
	}

	else if (first == "Square Root" || first == "Square root" || first == "square root" || first == "SQUARE ROOT" || first == "sqrt" || first == "Sqrt" || first == "SQRT" || first == "RADICAL" || first == "radical" || first == "Radical" || first == "Root" || first == "root" || first == "ROOT")
	{
		system("cls");
		cout << radical(d);
	}

	else if (first == "square" || first == "Square" || first == "SQUARE")
	{
		system("cls");
		cout << square(d);
	}

	cout << endl;
	system("pause");
}

//functions----------------------------------------------------------------------------------------------------------------------------------------------
double add(double &d,double &e)
{

	return d + e;
}

double subtr(double &d, double &e)
{

	return d - e;
}
double multip(double &d, double &e)
{
	

	return d*e;
}
double divi(double &d, double &e)
{
	
	return d / e;
}

double radical(double &d)
{
	
	return sqrt(d);
}

double square(double &d)
{
	
	return d*d;
}
I think the problem relies here:
1
2
3
4
5
6
7
8
9
10
11
12
if (ans == "y")
{
    cout << "Enter your second number: ";
    cin >> e;
    cout << "Enter the operation you wanna perform: ";
    getline(cin, first);
}
else //This function
{
    cout << "Enter the operation you wanna perform: ";
    getline(cin, first);
}


You did an if(){} and an else{} function. Your else was blocking the input to be retrieved for the input conditions.
so how should i fix this?
Topic archived. No new replies allowed.