2 doubles

Nov 22, 2015 at 4:23pm
Hi, I have 361 two double integers stored as a list in a .txt file. When i run the programme the first double integer joins the second double integer on the same line which I don't want. Anyone know how to fix this?
Nov 22, 2015 at 4:35pm
What's a double integer? Can you give a sample on what your file looks like?
Nov 22, 2015 at 8:31pm
int rowCounter = 1;
double var1;
double var2;

inputFile >> var1;
inputFile >> var2;

while (!inputFile.fail())
{

cout << setw(3) << rowCounter;
cout << " " << setw(3) << var2;
cout << " " << setw(3) << var1;

rowCounter++;
Nov 23, 2015 at 3:16pm
First of all, variables of type double are real number (with decimal places), not integers. They are really double floats, not double ints.

But to answer your question, you need to write a new line between your variable prints. You do this by using the endl statement.

1
2
cout << " " << setw(3) << var2 << endl;
cout << " " << setw(3) << var1;


For correctness, endl is actually a function taking a single argument that is inserted into a stream, but you'll learn about that as you get more experience with C++.

The cout stream and the endl function are both found in <iotream> within the std namespace, so they would correctly be called std::cout and std::endl.
Topic archived. No new replies allowed.