Do While Program

Hey guys,
Just starting to learn C++ language. Hope you guys can help me a way or other since every forum I have joined has been a huge help with me. :)

I have an assignment that would like to develop a C++ program that would perform a selection structure. The assignment is to present a user with a menu that would convert Celsius into Fahrenheit and back, and Pounds to Kilos, and back.
This is what I got.

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


int main(void)
{
	double Celsius;
	double Fahrenheit;
	double Pounds;
	double Kilograms;
	float B;
	int A;

	cout << "Pick the number of the program you would like to use" << endl;
	cout << "1.) Program Converting from Celsius to Fahrenheit" << endl;
	cout << "2.) Program Converting from Fahrenheit to Celsius" << endl;
	cout << "3.) Program Converting from Pounds to Kilograms" << endl;
	cout << "4.) Program Converting from Kilograms to Pounds" << endl;

	cin >> B;

	{
		do

		cout << "Welcome to the Program Converting from Celsius to Fahrenheit" << endl;
		cout << "Input the Degrees (in Celius) and press Enter" << endl;
		cin >> Celsius;
		Fahrenheit = (Celsius(9.0/5.0)) + 32;
		cout << " Degrees Fahrenheit = " << Fahrenheit << endl;
		cin >> B;
		while (A == 1);
	}
	{
		do

		cout << "Welcome to the Program Converting from Fahrenheit to Celsius" << endl;
		cout << "Input the Degrees (in Fahrenheit) and press ENTER:" << endl;
		cin >> Fahrenheit
			Celsius = (Fahrenheit - 32) * (5.0/9);
		cout << "Degrees Celsius = " << Celsius << endl;
		while (A == 2);
	}
	{
		do

		cout << "Welcome to the Program Converting from Pounds to Kilograms" << endl;
		cout << "Input the Pounds (lbs) and Press Enter" << endl;
		cin >> B;
		Kilograms = 2.2 * (Pounds);
		cout << "Kilograms = " << Kilograms << endl;
		while (A == 3);
	}
	{
		do
		cout << "Please enter the weight in Kilograms (kg) and press Enter" << endl;
		cin >> Kilograms;
		Pounds = Kilograms * (1/2.2);
		cout << "Pounds = " << Pounds << endl;
		while (N == 4);
	}
	system ("pause");

}

These are the errors:
1>c:\users\ce sharp\documents\visual studio 2010\projects\lab3\lab3\lab3.cpp(27): error C2061: syntax error : identifier 'cout'
1>c:\users\ce sharp\documents\visual studio 2010\projects\lab3\lab3\lab3.cpp(29): error C2064: term does not evaluate to a function taking 1 arguments
1>c:\users\ce sharp\documents\visual studio 2010\projects\lab3\lab3\lab3.cpp(38): error C2061: syntax error : identifier 'cout'
1>c:\users\ce sharp\documents\visual studio 2010\projects\lab3\lab3\lab3.cpp(40): error C2146: syntax error : missing ';' before identifier 'Celsius'
1>c:\users\ce sharp\documents\visual studio 2010\projects\lab3\lab3\lab3.cpp(48): error C2061: syntax error : identifier 'cout'
1>c:\users\ce sharp\documents\visual studio 2010\projects\lab3\lab3\lab3.cpp(57): error C2061: syntax error : identifier 'cin'
1>c:\users\ce sharp\documents\visual studio 2010\projects\lab3\lab3\lab3.cpp(60): error C2065: 'N' : undeclared identifier
1>c:\users\ce sharp\documents\visual studio 2010\projects\lab3\lab3\lab3.cpp(60): fatal error C1903: unable to recover from previous error(s); stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Please help.
Last edited on
Do/While Structure:
1
2
3
do {
   // ...
} while (condition);


Don't forget the semicolon after the while statement either.

P.S. to display code, it's all lowercase like [code]
Listen to the complier. You should take a google search about Error Id (Eg C2061).
Those are compiling errors.
And, wrap your code between two code tags (Click Edit and you'll see a format menu on the right)

Hope this helps.
TY GUys, it worked.
I think your code would be much better using a switch statement, rather than those do loops. Each case clause should call a function to carry out that particular menu option. The menu itself should be in a function, and should have a quit option.
Ya, using do/while loops is not indicated here. Remember, the do/while will execute all the code within it AT LEAST once no matter if the test expression is true or not. A switch would work, or 4 while loops. A series of if/else would work as well.
A switch that calls a function for each case is the tidiest way of doing it. While is no good :

while (N == 4)

should just be an if statement, but a switch is much tidier & better. Also put the whole thing in a loop that makes use of a bool. Here is some code I did to help someone else:

http://www.cplusplus.com/forum/beginner/84889/#msg455481
Hmm, ya I see your point about the whiles. They could work if you included an exit condition, but not the best solution at all.
Topic archived. No new replies allowed.