This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
void testDim(double bL, double bW, double bH, double jD, double jH);
void output(bool boolean, double bL, double bW, double bH, double jD, double jH);
ofstream outFile;
int main()
{
double boxL, boxW, boxH, jarD, jarH;
ifstream inFile;
inFile.open("input.txt");
while(inFile >> boxL >> boxW >> boxH >> jarD >> jarH)
{
testDim(boxL, boxW, boxH, jarD, jarH);
}
return 0;
}
void testDim(double bL, double bW, double bH, double jD, double jH)
{
bool boolean;
if(jH < (bH - 0.25))
{
if(jD < (bL - 0.25))
{
boolean = true;
}
else if(jD < (bW - 0.25))
{
boolean = true;
}
}
else if(jD < (bH - 0.25))
{
if(jH < (bW - 0.25))
{
boolean = true;
}
else if(jH < (bL - 0.25))
{
boolean = true;
}
}
else
{
boolean = false;
}
output(boolean, bL, bW, bH, jD, jH);
}
void output(bool boolean, double bL, double bW, double bH, double jD, double jH)
{
outFile.open("output.txt");
if(boolean == true)
{
outFile << bL << "\t" << bW << "\t" << bH << "\t" << jD << "\t" << jH << "\t" << "Yes" << endl;
}
else
{
outFile << bL << "\t" << bW << "\t" << bH << "\t" << jD << "\t" << jH << "\t" << "Yes" << endl;
}
}
Summary: I have a file to read multiple lines of multiple doubles from. Then, those values have to be rewritten to another file, along with text saying some calculations were a success or not (outputting "yes" or "no" to the outFile). My problem is that either the inFile is not advancing to the next line after reading the last value from the first line, or my while loop is only iterating once, OR there's some weird buffer thing going on. My outFile has all the correct test data for the first line, but there's only one line when there should be multiple.
Subreddit
Post Details
- Posted
- 5 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/programming...