Hello leewilliam236,
Thank you for the input file it was a big help.
This may work for you or be a starting point to work out what you want.
1 2
|
std::cout << " " << std::left << std::setw(20) << firstname[count] + " " + lastname[count];
std::cout << std::right << std::setw(10) << std::setprecision(2) << std::fixed << std::showpoint << area << std::endl;
|
When I started working with files I came up with this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
std::string iFileName{ "" }; // <--- Put input file name here.
std::ifstream inFile;
inFile.open(iFileName);
if (inFile.is_open())
{
// I comment out these lines when I know it is working.
std::cout << "\n File " << iFileName << " is open" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(2)); // <--- Needs header files chrono" and "thread".
}
else
{
std::cout << "\n File " << iFileName << " did not open" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(3)); // <--- Needs header files chrono" and "thread".
exit(1); // <--- Exits program because there is no reason to continue.
}
|
It is always a good practice to make sure that the file is open before trying to use it. What code you come up with is up to you. there are several ways of doing this. Some peple will put the main part of the program inside the if statement, but I like to keep things separate. Once you understand how all this works the code can be shortened. By then you should understand enough to figure it out.
I made one other change. I set
PI = M_PI
which comes from the "<math.h>" header file which comes from the "<cmath>" header file. The only way to use these built in "#defines" is to use "#define _USE_MATH_DEFINES" before you include "<cmath>", i.e.,
1 2
|
#define _USE_MATH_DEFINES
#include <cmath>
|
I think this works, it has been awhile since I worked with it. Actually I changed the "<cmath>" file and put the "#define _USE_MATH_DEFINES" right before the "#include <math.h>"this way it is always available for me. Editing the "<cmath>" file may not be easy if the directories and sub directories are "read only" protected.
Using PI with a greater precision did change the numbers in the final output.
Hope that helps,
Andy