### For Loop Troubles

Hello,

My instructor gave an assignment that goes like this:

"Use a for loop to generate a table similar to the following table. The first row of the table should be for 5/32 inch and it should end at 1 inch (32 thirty-seconds). Inside the loop, calculate the decimal equivalent in inches, determine the next bigger and the closest wrench sizes in mm, and calculate the differences between the two wrenches in inches.

There are 25.4 mm in one inch.

 ``123456789101112131415161718192021222324252627282930`` `````` Size Size Next Bigger Difference Closest Difference (Inches) (Inches) Metric (mm) (Inches) Metric(mm) (Inches) 5/32 0.156 4 0.001 4 0.001 6/32 0.188 5 0.009 5 0.009 7/32 0.219 6 0.017 6 0.017 8/32 0.250 7 0.026 6 -0.014 9/32 0.281 8 0.034 7 -0.006 10/32 0.312 8 0.002 8 0.002 11/32 0.344 9 0.011 9 0.011 12/32 0.375 10 0.019 10 0.019 13/32 0.406 11 0.027 10 -0.013 14/32 0.438 12 0.035 11 -0.004 15/32 0.469 12 0.004 12 0.004 16/32 0.500 13 0.012 13 0.012 17/32 0.531 14 0.020 13 -0.019 18/32 0.562 15 0.028 14 -0.011 19/32 0.594 16 0.036 15 -0.003 20/32 0.625 16 0.005 16 0.005 21/32 0.656 17 0.013 17 0.013 22/32 0.688 18 0.021 17 -0.018 23/32 0.719 19 0.029 18 -0.010 24/32 0.750 20 0.037 19 -0.002 25/32 0.781 20 0.006 20 0.006 26/32 0.812 21 0.014 21 0.014 27/32 0.844 22 0.022 21 -0.017 28/32 0.875 23 0.031 22 -0.009 29/32 0.906 24 0.039 23 -0.001 30/32 0.938 24 0.007 24 0.007 31/32 0.969 25 0.016 25 0.016 32/32 1.000 26 0.024 25 -0.016``````

I got the first two row, but am having trouble with the math for the 3rd column and then how to make the decimals for the 4th. Then I figure the fifth is like the third. Last, how do I do the math for the 6th row? Very frusturated right now with this. Please help.

Here is my program:

 ``1234567891011121314151617181920212223242526272829303132333435`` ``````using namespace std; int main() { //State Variables double i, j; //Cout Statements cout.setf(ios::fixed); cout.precision(3); cout << " Size Size Next Bigger\n " ; cout << " (Inches) (Inches) Metric (mm)" << endl; //For Loop for (int i=5; i<=32; i+=1) { j = (i/32.0); cout << setw(6) << i << "/32 " << setw(10) << j << endl; } system("PAUSE"); return 0; }``````
Last edited on
3rd column: convert inches to mm and do ceil()
4th column: convert mms from third column back to inches and substract original value
5th column: convert inches to mm and do round()
6th column: convert mms from fifth column back to inches and substract original value
Topic archived. No new replies allowed.