half program is working it is working for firs two not for last 2 it stop working after or during secong do while second do whi

/* Qamarulhuda Khairullah */
/* EGR 126 Computer Programming for Engineers */
/* Dated: 11/1/2011 */
/*LAB # 3
Develop and run a C++ program to perform the following:
A. Present the user with a menu to select one of the following options:
1. Convert from Celsius to Fahrenheit
2. Convert from Fahrenheit to Celsius
3. Convert from pounds to kilograms
4. Convert from kilograms to pounds
9. EXIT */


#include <cmath>
#include <iostream>

using namespace std;
int main(void)

{
float Celsius;
float Fahrenheit;
float a;
float lb;
float Kilogram;
int N;

cout << "Hello. Welcome to the Temperature Conversion program" << endl;
cout << "Enter any option"<<endl;
cout << "1.Convert from Celsius to Fahrenheit" <<endl;
cout << "2.Convert from Fahrenheit to Celsius" <<endl;
cout << "3.Convert from pounds to kilograms" <<endl;
cout << "4.Convert from kilograms to pounds" <<endl;
cin >> a;

do

{
cout << "Please enter the degrees in Celsius and press ENTER: " << endl;
cin >> Celsius;
Fahrenheit = ((9.0/5)*Celsius) + 32;
cout << " Degrees Fahrenheit = " << Fahrenheit << endl;
cin>>N ;
}

while (N==1);
do
{
cout << "Please enter the degrees in Fahrenheit and press ENTER: " << endl;
cin >> Fahrenheit;
Celsius = (5.0/9) * (Fahrenheit - 32);
cout << " Degrees Celsius = " << Celsius << endl;
cin>> N;
}
while (N==2);

do
{
cout << "Please enter the weight in pounds and press ENTER: " << endl;
cin >> lb;
Kilogram = 2.2 * lb;
cout << "Kilogram = " << Kilogram << endl ;
cin>>N;
}
while(N==3);

do
{
cout <<"Please enter the weight in Kilograms and press ENTER: " << endl;
cin >> Kilogram;
lb = Kilogram / 2.2 ;
cout << "Weight in Pounds = " << lb << endl;
cin>>N;
}
while(N==4);

return 0;

}
do ... while loops are not correctly the way you use it here. Use switch for that:

http://www.cplusplus.com/doc/tutorial/control/


Add a do ... while loop that begins before cout << "Enter any option"<<endl; and ends the last calculation: do { ... } while(a != 9); // You need to add the exit condition!

You may omit cin>>N;


Please use code tags: [code]Your code[/code]
See: http://www.cplusplus.com/articles/z13hAqkS/
Last edited on
Topic archived. No new replies allowed.