#Trouble using setw() in a for loop

4 messages · Page 1 of 1 (latest)

edgy talon
#

I wrote the following code to create a table that displays meters and converts it to feet. However, my setw() in my for loop isnt spacing out properly like outside the loop. Any help would be appreciated! :)

#include <iostream>
#include <iomanip>

using namespace std; 
int main() {

  int meters;
  double feet;
  
  std::cout << fixed;
  std::cout << left;

  std::cout << "Meters " << setw(10) << "Feet" <<endl;
  
  for (int meters = 1; meters < 16; meters++) // for loop  choosing how large you want the table to be by changing the middle condition integer
  {
    feet = meters * 3.280;
    
    std::cout << meters << setw(10) << setprecision(3) << feet << endl;

  
  }

}
#

I want it to look like this

kind gardenBOT
#

@edgy talon

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.

#

@edgy talon

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.