Trying to make a nested loop program.

I have a program I am trying to do.. its a basic convert feet to inches or inches to feet. It needs to have a zero as the sentinel to boot out of the program and be able to warn the user about entering a negative number. I can get it to exit the program on entering a zero but past that it wont do any calculations. Here is my code, can someone please help me with it?

#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{

double value, feet, inches, inch, measurement, f, i, F, I;
char unit;

cout << setprecision(5) << showpoint << endl;

do {

cout << "Enter value(0 to stop):" ;
cin >> value;
cout << endl << endl;

cout << "Was the value f)eet or i)nches? ";
cin >> unit;
cout << endl << endl;


if (( unit == f) || ( unit == F ))
{
inches = value * 12;

cout << inches << " inches = " << value << " feet " << endl << endl;
}
else if (( unit == i) || (unit == I ))
{
feet = value / 12;

cout << feet << " feet = " << value << " inches " << endl << endl;
}
}
else if ( value < 0 )
{
cout << " Error negative Value " << value <<
" Inches or Feet cannot be negitive " << endl;
}
else
{
cout << endl;
cout << " Error Invalid unit " << unit << " entered."
<< " Must be f)eet or i)nches. " << endl << endl;
}

} while ( value != 0 );

return 0;
}
Your tests to determine if 'unit' is 'f' or 'i' are incorrect.
When you put unit == //something, that something needs to be a char. Fix this by putting the letters each inside apostrophes, like this:
 
if(unit == 'i' || unit == 'I')


***************************************************

You have an extra bracket after the if-statement testing if they declared the unit to be inches.

***************************************************

You need to execute the "'x' inches = 'y' feet" after you determine if they input a non-negative number. Put the (value < 0) if test at the start.

***************************************************

If you can, make the exit-value equal '-1' instead of '0'

Topic archived. No new replies allowed.