Program finishes at second cin

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>
#include<cstring>
using namespace 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();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>
#include<cstring>
using namespace 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()
Thank you very much :)
i think its because you are trying to enter strings on the first cin when you declare it as char
Topic archived. No new replies allowed.