I am having trouble on figuring out how to read each line from a txt file into a decimal variable, the only argument that works for what I'm doing is char.
Here's the instructions for my HW.
https://drive.google.com/file/d/1KZqoNS8a4EqRKqSmpUeRlGQAKupa46hF/view?usp=sharing
Here's the txt file.
https://drive.google.com/file/d/1KrLWYRDu7sPKtdOOGb2SCwP5cyaVjjI0/view?usp=sharing
I actually need help for all of the steps but I'm stuck with reading each line into a decimal variable.
Here's my current code.
#include "stdafx.h"
#include <iostream> // standard console i/o
#include <string> // string library
#include <iomanip> // output formatting
#include <fstream>
using namespace std; // standard namespaces
int main()
{
ifstream inFile; // handle to input file
string strFileName = // file name
"CIS022_S2019_Lab5a_data.txt";
char cChar; // character read from file
string strFileData; // data read from file
string strTotal = // output of total value
"Total value: %.4f";
double fFileData;
inFile.open(strFileName); // open the input file
if (inFile.is_open()) // did the file open
{
inFile.get(cChar); // get the first char of the file
while (!inFile.eof()) // while not end of file
{
cout << cChar; // display the character
inFile.get(cChar); // get the next character
}
inFile.close(); // close the file
}
else
printf("File %s not found. \n", strFileName.c_str()); // file not found error message
cout << endl << endl; // blank line
system("Pause"); // pause before closing
return 0;
}
If you check the instructions in the link above you will see that the console does not display the txt file, but I also don't know how to read it without displaying it. I've experimented with removing cout in my while section but I don't think that it works and the only thing that runs is my blank line and system pause at the end. Please help. (No programming experience at all)