The goal of this project is to output the following information as follows:
34.5
38.6 4.1
42.4 3.8 close
46.8 4.4 big change.
The values of the first colunm are obtain from a file called: tempInput.txt, and then the information is calculated, and it is output on a different file called tempOutput.txt.
The tempInput.txt containg those numbers as follows:
34.5 38.6 42.4 46.8
I am able to obtain the correct output if I use the numbers already assigned. However, if I change the number on the tempInput.txt file, my output on the tempOutput.txt file is un aligned.
I have tried to twick it in different ways, but I am unable to the correct formatting output with any values of my choice.
I will appreciate any information that will allow me to fix the formatting output with what ever number I use on the tempInput.txt file.
The code I have so far is as follows:
Thank you again!!
34.5
38.6 4.1
42.4 3.8 close
46.8 4.4 big change.
The values of the first colunm are obtain from a file called: tempInput.txt, and then the information is calculated, and it is output on a different file called tempOutput.txt.
The tempInput.txt containg those numbers as follows:
34.5 38.6 42.4 46.8
I am able to obtain the correct output if I use the numbers already assigned. However, if I change the number on the tempInput.txt file, my output on the tempOutput.txt file is un aligned.
I have tried to twick it in different ways, but I am unable to the correct formatting output with any values of my choice.
I will appreciate any information that will allow me to fix the formatting output with what ever number I use on the tempInput.txt file.
The code I have so far is as follows:
Thank you again!!
Code:
#include <iostream> #include <cmath> #include <iomanip> #include <fstream> using namespace std; int main(){ // Input variables float tempValue1; float tempValue2; float tempValue3; float tempValue4; ifstream inData; ofstream outData; // Local Varialbles float tempDif1; float tempDif2; float tempDif3; inData.open("tempInput.txt"); outData.open("tempOutput.txt"); // Read Values from the file inData >> tempValue1 >> tempValue2 >> tempValue3 >> tempValue4; // Calculate values tempDif1 = fabs(tempValue1 - tempValue2); tempDif2 = fabs(tempValue2 - tempValue3); tempDif3 = fabs(tempValue3 - tempValue4); // output results outData << fixed << showpoint << setprecision(1); outData << setw(4) << tempValue1 << endl; outData << setw(4) << tempValue2 << setw(8) << tempDif1; if (tempDif1 < 4) outData << setw(10) << "close" <<endl; else if (tempDif1 > 4.3) outData << setw(15) << "big change" << endl; outData << setw(4) << tempValue3 << setw(8) << tempDif2; if(tempDif2 < 4) outData << setw(10) << "close" << endl; else if (tempDif2 > 4.3) outData << setw(15) << "big change" << endl; outData << setw(4) << tempValue4 << setw(8) << tempDif3; if(tempDif3 < 4) outData << setw(10) << "close" << endl; else if (tempDif3 > 4.3 ) outData << setw(15) << "big change" << endl; inData.close(); outData.close(); return 0; }
Comment