getline function problem

I have this problem with the getline function where the output is clumped together:

This program calculates your weight on nine planets:
1 Mercury
2 Venus
3 Earth
4 Mars
5 Jupiter
6 Saturn
7 Uranus
8 Neptune
9 Pluto
Enter your name: TEST
Enter weight: 100
Enter planet number (1-9): 9
Your weight on Pluto is: 50
P
Do you want to enter another planet? (Y/N): N
Do you want to switch user? (Y/N): Y
Enter your name: Enter weight:





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
/* planet

*/

//planet.cpp – displays a grade based on the total number of points
//entered by the user

#include <iostream>
#include <string>

using std::cout;
using std::cin;
using std::endl;
using std::string;

int main()
{
	//declare variables and arrays
	double otherWeight = 0.0;
	double weight = 0.0;
	string name = " ";
	string planet[9] = {"Mercury", "Venus", "Earth",  "Mars", "Jupiter", "Saturn",  "Uranus", "Neptune", "Pluto"};
	double relGrav[9] = {0.4155, 0.8975, 1.0, 0.3507, 2.537, 1.0677, 0.8947, 1.1794, 0.5};
	string statement[9] = {"M", "V", "E", "Ma", "J", "S", "U", "N", "P"};
	char anotherName = ' ';
	int x = 0;
	char anotherPlanet = ' ';
 
	//get input
	cout << "This program calculates your weight on nine planets:" << endl;
	cout <<	"1 Mercury" << endl;
	cout << "2 Venus" << endl;
	cout << "3 Earth" << endl;
	cout << "4 Mars" << endl;
	cout << "5 Jupiter" << endl;
	cout << "6 Saturn" << endl;
	cout << "7 Uranus" << endl;
	cout << "8 Neptune" << endl;
	cout << "9 Pluto" << endl;
	do 
	{
	cout << "Enter your name: ";
	getline(cin, name);
	cout << "Enter weight: ";
	cin >> weight;
	do 
	{
		
		cout << "Enter planet number (1-9): ";
		cin >> x;
		
		otherWeight = relGrav[x - 1] * weight;
		cout << "Your weight on " << planet[x - 1] << " is: " << otherWeight << endl;
		cout << statement[x - 1] << endl;
		

	cout << "Do you want to enter another planet? (Y/N): ";
	cin >> anotherPlanet;
	anotherName = toupper(anotherPlanet);

	}	while (anotherPlanet != 'N');

		cout << "Do you want to switch user? (Y/N): ";
	cin >> anotherName;
	anotherName = toupper(anotherName);

	} while (anotherName != 'N');
	return 0;
}  //end of main function


Does anyone know how i can fix it?
It seems like there is something still left in the input stream that is being read by getline. @ Line number 64 try changing the code to

(cin >> anotherName).get()

Let me know if that fixes your problem(No compiler on this computer so I can't run your code.)
Topic archived. No new replies allowed.