Hey guys, can you help me with this problem I'm experiencing, when I execute my program it stops after 2 cins, that means it won't let me input line and equation and I'm still a beginner and have no idea why.
#include<iostream>
#include<cstring>
usingnamespace std;
void inLine()
{
char point;
cout << "Please select a name for your point: ";
cin >> point;
double x, y;
cout << "Please input the coordinates of " << point << " : ";
cin >> x >> y;
char line;
cout << "Please select a name for your line: ";
cin >> line;
string equation;
cout << "Please write the linear equation of " << line <<" : ";
getline (cin, equation);
}
int main ()
{
inLine();
}
#include<iostream>
#include<cstring>
usingnamespace std;
void inLine()
{
char point;
cout << "Please select a name for your point: ";
cin >> point;
cin.ignore(); //here
double x, y;
cout << "Please input the coordinates of " << point << " : ";
cin >> x >> y;
char line;
cout << "Please select a name for your line: ";
cin >> line;
cin.ignore(); //here
string equation;
cout << "Please write the linear equation of " << line <<" : ";
getline (cin, equation);
}
int main ()
{
inLine();
}
When you enter a character, the newline character when enter is pressed is left in the input buffer. So ignore it with cin.ignore()