I wrote a selling ticket program for a concern into a text file name "Sales.txt" to show the TotalValue with the following format:
21
30
40
24
87
44
51
29
58
20
Totally, I have 10 values.
However, my new assignment asks me to make a new program that read the values that I caputed in the text file into an array.
This is my new program:
Bold Text Here #include <iostream>
include <string>
include <fstream>
using namespace std;
int main()
{
ifstream inputFile;
string filename;
int number;
cout << "Enter file name: ";
cin >> filename;
inputFile.open(filename.c_str());
if (inputFile)
{
while (inputFile >> number)
{
cout << number << endl;
}
inputFile.close();
}
else {
cout << "Error";
}
return 0;
}
I dont know where I am wrong, but I can't open my file when I run and type Sales.txt. It keeps saying error or shows only the first value.
please help me with this.