-
new way of doing it
Code:
deduction = 0;
if(deductiontype.compare("Itemized") == 0)
{
while(1)
{
input>> deditem;
if(deditem==0)
break;
deduction =deduction+ deditem;
}
}
im trying to figure out if there a different way to put while(1)
which equalls true but is there a different way without putting 1 in there
-
Code:
do{
cin >> ded;
deduction+=ded;
}while ( ded != 0);
-
For starters, format your code properly, e.g.,
Code:
deduction = 0;
if (deductiontype.compare("Itemized") == 0)
{
while (1)
{
input >> deditem;
if (deditem == 0)
break;
deduction = deduction + deditem;
}
}
Now, it is easy to see that you can simplify to:
Code:
deduction = 0;
if (deductiontype.compare("Itemized") == 0)
{
while ((input >> deditem) && deditem != 0)
{
deduction += deditem;
}
}
Incidentally, if you were just looking to replace the 1, then replace it with true, or you can use for (;;) instead.