Apr 1, 2013 at 12:00am UTC
you can use if statements to check if there is a number that is not zero, set the decimal places to two, else just print 0
Apr 1, 2013 at 8:34pm UTC
set the precision if it is not zero. otherwise just directly output '0'
Apr 1, 2013 at 9:13pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
for (int i = 0; i < SLSPRNS; i++)
{
cout << "Salesperson " << i+1 << " |" ;
for (int j = 0; j < SLSPRDT; j++)
{
if (sales[i][j] != 0)
{
cout << fixed << showpoint << setprecision(2) << setw(14) << sales[i][j] << " |" ;
}
else
{
cout << setprecision(0) << setw(14) << '0' << " |" ;
}
}
cout << endl;
}
maybe that.
Last edited on Apr 1, 2013 at 9:16pm UTC
Apr 2, 2013 at 10:01am UTC
That did it. The trick was to cout the array inside the if statement, I see now.
Thank you.