Error: Expecting a while?

Hi guys,
me and my friend have both started learning to write C++ and are setting eachother tasks to complete and then compare the programs (thought it would help learning). the task was to create a simple program that could work out a value in a physics equation. This is what ive come up with so far (i know i haven't put any equations in yet, but instead i just wanted to see if my switch worked):


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
#include <iostream>

using namespace std;

int main()
{
	system("TITLE Physics Calculator");

	char cChar;

do
{
	cout << ("This simple tool will allow you to solve any value in the F=G*m1*m2/r^2 equation") << endl;
	cout << endl;
	cout << ("Press the character corresponding with the value you want to solve:") << endl;
	cout << endl;
	cout << ("(f) F = Force") << endl;
	cout << ("(1) m1 = mass of object 1") << endl;
	cout << ("(2) m2 = mass of object 2") << endl;
	cout << ("(r) r = distance between two centre of masses") << endl;
	cin >> cChar;
	
	switch (cChar)
	{
	case 'f':
		cout << "F has been selected";
		break;
	case 'r':
		cout << "r has been selected";
		break;
	case '1':
		cout << "1 has been selected";
		break;
	case '2':
		cout << "2 has been selected";
		break;

	}


	system("pause");
	return 0;

}
	

}


any help to why the "Expecting a While" error or any improvements on the program would be greatly appreciated :)
closed account (yUq2Nwbp)
i dont see here your while............you used this construction

do
{
} while(condition)

........where is your while???:)
ok, i get that. i understand how to do a condition if its numeric:

 
while(x<10)


but what would my condition be in my case?
You could try program in an exit key such as 'X' and have your while condition as while( cChar != 'X' );.

There is a better way to do it, but at the moment it alludes me.

Also I see you are using system("pause"), in the current context it's perfectly fine but there are many evils associated with it. You can find about why it's bad and an alternative here:

http://www.cplusplus.com/forum/beginner/1988/

Good luck, and I hope this helps!
Last edited on
You'll also want to move your system("pause"); and return 0; out of the the do-while loop because otherwise after the first iteration of the loop the program will close.
Topic archived. No new replies allowed.