So I have a new problem with a code I requested help with earlier. I got the loop to work and the conversions working properly as well. However, how the table outputs, the first column is 1 to 20, and I want it aligned right. I'm using cout << right in int main() which works for the table as a whole, but numbers 1 through 9 are not aligning right, so I did this:
1 2 3 4 5 6 7 8
for (int ROWS = 1; ROWS < 21; ROWS++) //creates conversion table based on TEMP and INC inputs
{
cout << ROWS << setw(10) << ((TEMP+=INC)-INC) << setw(10) << ((FAHR+=INC)-INC) << setw(10)
<< ((KEL+=INC)-INC) << setw(10) << (((RAN+=INC)-INC)*1.8) << endl;
if (ROWS < 10) //creates space for rows 1-9 for proper alignment
cout << " ";
}
cout << endl;
It works, but only for 2 to 9, and also indents 10, I'm assuming it has to do with it not being included in the first iteration, and going 2 through 10. It doesn't make conceptual sense in my head why it would do this, since I'm not saying "the first ten rows after first iteration." I'm saying "IF the row is initialized as 1 to 9, THEN add a space." I can see how that would skip one based on how loops iterate, but it shouldn't be counting ten as well. I'm guessing then there is another statement I can use to create the same effect but properly, since my instructors example does it (note I only have the output example, not the code itself).
You are adding a space AFTER you print the statement. This means it only affects the rows AFTER row 1-9, i.e. rows 2-10. Move lines 5-6 to before line 3.
Ahah! Same problem I had when I first declared and initialized my conversion variables. I did at the beginning before TEMP and INC were reassigned with the input. That actually happens a lot. I should try moving stuff around before asking more often. Anyway, thanks!