Can someone help me write the correct logic statements so that I can output the
ID: 3636198 • Letter: C
Question
Can someone help me write the correct logic statements so that I canoutput the name and three decimal numbers in ascending order?
Thank you.
Here is the code:
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
int main()
{
double num1, num2, num3;
string fName, lName;
ifstream inFile;
ofstream outFile;
cout << " **Program outputs your full name and some numbers in ascending order. All input "
<< "read from a file.!**";
cout << " ";
cout << endl;
inFile.open("data.txt"); // open the input file
//check to make sure it's ok!
if (!inFile)
{
cout << " Cannot open the input file. Something is wrong!**";
cout << " The program terminates.** " << endl;
cout << " " << endl;
system("pause");
return 1;
}
outFile.open("results.txt"); //open the output file
cout << " Processing data...";
inFile >> fName >> lName;
cout << " Processing data...";
inFile >> num1 >> num2 >> num3;
//output full name to a file
outFile << fName << " " << lName << endl;
// begin conditionals to order numbers in ascending order
if (num1 < num3) // num1 less than num3
{ outFile << fixed << showpoint << setprecision(2) << num1 << ", ";
if (num3 < num2) // compare num2 and num3
outFile << fixed << showpoint << setprecision(2) << num3 << ", " << num2 << endl;
else
outFile << fixed << showpoint << setprecision(2) << num2 << ", " << num3 << endl;
}// end inner-if
}
else
{
outFile << fixed << showpoint << setprecision(2) << num3 << ", " << endl;
if (num1 < num2)
outFile << fixed << showpoint << setprecision(2) << num1 << ", " << fixed << showpoint << setprecision(2) << num2 << endl;
else
outFile << fixed << showpoint << setprecision(2) << num2 << ", " << fixed << showpoint << setprecision(2) << num1 << endl;
}
{
if (num2 < num3)
outFile << fixed << showpoint << setprecision(2) << num2 << ", " << endl;
if (num1 < num3)
outFile << fixed << showpoint << setprecision(2) << num1 << ", " << fixed << showpoint << setprecision(2) << num3 << endl;
else
outFile << fixed << showpoint << setprecision(2) << num3 << ", " << fixed << showpoint << setprecision(2) << num1 << endl;
}
else
{
if (num1 < num2)
outFile << fixed << showpoint << setprecision(2) << num1 << ", " << fixed << showpoint << setprecision(2) << num3 << endl;
else
outFile << fixed << showpoint << setprecision(2) << num2 << ", " << fixed << showpoint << setprecision(2) << num1 << endl;
*/
inFile.close();
outFile.close();
system("pause");
return 0;
}