I fail to understand cin while looping. (Total noob)

I'm a beginner programmer. I'm having trouble understanding why my code won't execute correctly. There's 2 main problems I'm encountering. My program is supposed to allow for a user to input whether they want to convert fahrenheit to celcius, celcius to fahrenheit or exit the program. If a letter is entered instead of an integer (specifically 1,2,3 for the corresponding function) it enters an infinite loop. The second problem occurs after the completion of the conversion, it asks the user to input 'y' or 'Y' as a character before continuing to clear the screen and return the user to the menu where they will select an option again. This is my code.

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
#include <iostream>
using namespace std;

//FUNCTION DECLARATIONS//
void menu(), clearScreen(), menuChoice(int choiceVar), starCreator(), celciusToFahrenheit(), fahrenheitToCelcius();

int main(){
	int choiceVar;
	while (choiceVar != 3){
		menu();
		cout << "Enter your choice";
		cin >> choiceVar;
		menuChoice(choiceVar);
	}
	return 0;
}

void menu(){
		starCreator();
		cout << "Welcome to Temperature Converter" << endl;
		cout << "1: Convert Fahrenheit to Celcius " << endl;
		cout << "2: Convert Celcius to Fahrenheit " << endl;
		cout << "3: Exit the Temperature Converter" << endl;
		starCreator();
}

void menuChoice(int choiceVar){
	switch (choiceVar){
	case 1:
		fahrenheitToCelcius();
		break;
	case 2:
		celciusToFahrenheit();
		break;
	case 3:
		break;
	default:
		cout << "That is not a valid choice" << endl;
		cout << "Please enter 1, 2 or 3" << endl;
		break;
	}
}

void fahrenheitToCelcius(){
	double temperatureVar, conversionVar;
	cout << "Enter a Temperature" << endl;
	cout << "Fahrenheit : ";
	cin >> temperatureVar;
	conversionVar = (temperatureVar - 32) * 5 / 9;
	cout << "That temperature in Celcius equates to : " << conversionVar << endl;
	clearScreen();
}

void celciusToFahrenheit(){
	double temperatureVar, conversionVar;
	cout << "Enter a Temperature" << endl;
	cout << "Celcius : " << endl;
	cin >> temperatureVar;
	conversionVar = (temperatureVar * 5 / 9) + 32;
}

void clearScreen(){
	char clearApproval;
	while (clearApproval != 'y' || clearApproval != 'Y'){
        cout << "Enter y or Y to continue" << endl;
        cin >> clearApproval;
	}
			for (int x=0; x<=100; x++)
				cout << endl;
}

void starCreator(){
	for (int stars = 0; stars < 100; stars++)
			cout << "*";
	cout << endl;
}


I apologize to anyone that is embarrassed for me and my lack of c++ prowess. I spent a lot of time researching this and trying to debug it. It's due tomorrow and I have other work to be finishing so I'm unable to spend any more time searching endless forums about why the cin won't allow me to re-assign it each iteration through the loop. I'm running Ubuntu by the way, so system.whatever won't work.
closed account (EwCjE3v7)
You also have an undefined value at the start. The value that choiceVar is undefined on the first loop into the while loop, so

1
2
3
4
5
6
7
8
9
10
int main(){
	int choiceVar = 0;
	while (choiceVar != 3){
		menu();
		cout << "Enter your choice";
		cin >> choiceVar;
		menuChoice(choiceVar);
	}
	return 0;
}


I always initialize my variables.
I'm attempting to understand that link, without success so far... but thanks MiiNiPaa!
Fr0zen1 - Yeah, I need to start doing that. I've been screwing with the program so much that my head is spinning. I've practically changed each line of code in order to find a way to attempt to make it work and I'm getting confused and aggravated. Thanks again for your help folks!
Topic archived. No new replies allowed.