I need to string names from a text file which the name will output no more than 29 characters and no commas. My output displays no commas, but i cant figure out how to count the characters and output no more than 29 characters in the name.
I think I just need to add a way to count the characters in the while loop.
Its the: VOID GETDATA(FSTREAM& IN, STRING& NAME, DOUBLE& ACRES, INT& JARS) funtion that i am have my problem.
Can somebody help me please....
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <E:\\CS-1410 (Fall2009)\\Bonus Project\\Popcorn.h>
using namespace std;
int main()
{
fstream InFile;
string Name;
int Jars;
double Acres;
//print header
PrintHeader();
//Open file to read
InFile.open("E:\\CS-1410 (Fall2009)\\Bonus Project\\BonusProj.txt",ios::in);
if (!InFile)
{
cout<<"Can't Open the input file.";
return 1;
}
//continue if Target is a character
while (!InFile.eof())
{
//get data
GetData(InFile, Name, Acres, Jars);
//print name
//cout<<setw(29)<<Name;
//print bar chart
// PrintStars(Jars/Acres);
// cout<<endl;
}
InFile.close();
cin.get();
return 0;
}
void PrintHeader(void)
{
cout<<setw(23)<<"Pop CoOp"<<endl;
cout<<"Farm Name"<<setw(30)<<"Production"<<endl;
cout<<setw(41)<<"Thousands of"<<endl;
cout<<setw(47)<<"Pint Jars per Acre"<<endl;
cout<<setw(53)<<" 1 2 3 4 5 6"<<endl;
cout<<setw(52)<<"---|---|---|---|---|---"<<endl;
}
/*void PrintStars(double NumStars)
{
if (NumStars>0)
{
cout<<'*'<<endl;
}
int Round(double x)
{
return x=((Jars/Acres)/TickMark+.5)
}*/
void GetData(fstream& In, string& Name, double& Acres, int& Jars)
{
char x=' ';
int count=0;
In.get(x);
while (x < 29 || x != ',' )
{
Name = Name + x;
In.get(x);
}
if (x == ',' || x >= 29)
{
In>>Acres>>Jars;
cout<<Name<<endl;
Name=" ";
In.get(x);
count=0;
Jars=0;
Acres=0;
}
}