loop problem

I have a segment that is SUPPOSED to execute an error message then restart the loop, but it tries to make you enter the variable again. What is wrong?

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
const bool FEET = true;
const bool INCHES = false;

int main()
{
bool feetOrInches;

double value = -1;
char type = ' ';

do
{
while(value < 0)
{
cout << "Enter value (0 to stop): ";
cin >> value;
if(value < 0)
cout << "Error! Value " <<
 value << " was entered. Inches or feet cannot be negative.\n\n";
}

if(value == 0) { break; }

while(toupper(type) != 'F' && toupper(type) != 'I')
{
cout << "Was the value (f) feet or (i) inches?: ";
cin >> type;
if(toupper(type) != 'F' && toupper(type) != 'I')
cout << "Error! Unit " << type << "was entered, must be f)eet or i)nches\n";

//Set the type
if(toupper(type) == 'F')
feetOrInches = FEET;
else if(toupper(type) == 'I')
feetOrInches = INCHES;
}

cout << endl << value;
if(feetOrInches == FEET) { cout << " feet = " << value*12 << " inches\n\n"; }
if(feetOrInches == INCHES) { cout << " inches = " << value/12 << " feet\n\n"; }
//Reset value and type so the loop will repeat correctly
value = -1;
type = ' ';

}while(value != 0);

return 0;
}
What do you want it to do?
I keep getting this:

Enter value (0 to stop): 258
was the value (f) feet ir (i) inches?: x
Error! Unit x was entered, must be f or i
was the value (f) feet ir (i) inches?:

I want it to just start over to the enter value line not the enter feet or inches line...I'm perfecting my error messages and inputs.
Topic archived. No new replies allowed.