this is what i have of my code so far:
i've also included attachments of some of the txt files i am using
i would just like to know how i could use the integer values within the text files and actually get the mean values for them etc..
very very greatful for any help
Code:
#include <fstream>
#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
using namespace std;
int main()
{ int c; // open
string str[20]; // string array
int i = 0, j = 0, last; // counter variables
ifstream myFile("figures1.txt"); // input file object
if (! myFile)
{ // open
cout << "Unable to open input file" << endl;
return -1;
} // close
while (! myFile.eof()) // loop through data
{ // open
if ((i+1) % 2 ==0) getline(myFile, str[i++]);
else getline(myFile, str[i++], '\t');
} // close
last = i; // last element #
i = 0;
while (i < last) // display records
{ // open
cout << "Choice Number:\t" << str[i++] << endl;
cout << "Company Name:\t" << str[i++] << endl;
} myFile.close(); // close
// close the file
cin >> c;
switch (c){
case 1: cout<< "you have selected company, Diago Plc\n"<< endl;
{
string str;
ifstream myFile("Diago plc.txt");
if (!myFile) // Always test file open
{
cout << "Error opening output file" << endl;
return -1;
}
while (! myFile.eof()) // Loop through lines
{
getline(myFile, str);
cout << str << endl;
}
myFile.close();
}
break;
case 2: cout<< "you have selected company, Sabmiller Plc\n"<<endl;
{
string str;
ifstream myFile("sabmiller plc.txt");
if (!myFile) // Always test file open
{
cout << "Error opening output file" << endl;
return -1;
}
while (! myFile.eof()) // Loop through lines
{
getline(myFile, str);
cout << str << endl;
}
myFile.close();
}
break;
case 3: cout<< "you have selected company, Associated British Foods Plc\n"<<endl;
{
string str;
ifstream myFile("associated british foods plc.txt");
if (!myFile) // Always test file open
{
cout << "Error opening output file" << endl;
return -1;
}
while (! myFile.eof()) // Loop through lines
{
getline(myFile, str);
cout << str << endl;
}
myFile.close();
}
break;
case 4: cout<< "you have selected company, Scottish and Newcastle Plc\n"<<endl;
{
string str;
ifstream myFile("scottish and newcastle.txt");
if (!myFile) // Always test file open
{
cout << "Error opening output file" << endl;
return -1;
}
while (! myFile.eof()) // Loop through lines
{
getline(myFile, str);
cout << str << endl;
}
myFile.close();
}
break;
case 5: cout<< "you have selected company, Tate and Lyle Plc\n"<<endl;
{
string str;
ifstream myFile("tate and lyle.txt");
if (!myFile) // Always test file open
{
cout << "Error opening output file" << endl;
return -1;
}
while (! myFile.eof()) // Loop through lines
{
getline(myFile, str);
cout << str << endl;
}
myFile.close();
}
break;
case 6: cout<< "you have selected company, Kerry Group Plc\n"<<endl;
{
string str;
ifstream myFile("kerry group.txt");
if (!myFile) // Always test file open
{
cout << "Error opening output file" << endl;
return -1;
}
while (! myFile.eof()) // Loop through lines
{
getline(myFile, str);
cout << str << endl;
}
myFile.close();
}
break;
default: cout << "you have not entered a valid choice"<<endl;
cout<<" please re-enter your choice"<<endl;
}
return 0;
}