There was more to the program than what I cut and pasted into the thread.
Following the name of each farm are two values: the number of acres in the farm and the number of jars of popcorn produced by the farm. The program uses these numbers to make a “bar” graph. The graph is actually comprised of stars with each star representing 25 jars per acre.
I managed to fix the name problem by simply finishing writing the program. I assigned the two numbers on each line to be acres and jars. This kept them from being put through the original FarmName loop.
Now for the new problems…
The first line in the graph is indented one space. The name is fine, but the actual graph itself is indented.
The other problem seems to lie within the formula for figuring out the number of stars. For all of the farms until the last one, the formula works. The last farm (This is the one that really matters) should have 7 stars. Instead, it has 12.
I can’t for the life of me figure out what’s wrong.
–DoperChic
DataSet
Orville’s Acres, 114.8 43801
Hoffman’s Hills, 77.2 36229
Jiffy Quick Farm, 89.4 24812
Jolly Good Plantation, 183.2 104570
Organically Grown Inc., 45.5 14683
This is the farm that really matters, 50.3 10000
Program
#include <string> // For strings
#include <fstream> // File input/output
#include <iostream>
const string HEADER1 = “Jessica M Kleiss CSC141-05 | Production in Hundreds |”;
const string HEADER2 = “Project #6 4/1/2002 | Of Pint Jars Per Acre |”;
const string HEADER3 = " | 1 2 3 4 5 6 |";
const string HEADER4 = " F A R M N A M E |—|---|—|---|—|---|—|";
const string DONE = “Job is finished”;
//const char BLANKS = ’ ';
//const char STARS = ‘*’;
char FarmName;
int count;
int count2;
int count3;
int number;
int counts;
int blanks;
float acres;
float jars;
float stars;
int main()
{
ifstream enterfile; // identifies enterfile as type ifstream
ofstream exitfile; // identifies exitfile as type ofstream
enterfile.open(“DataSet.txt”); // Gets data from DataSet.txt
exitfile.open(“Graph.txt”); // Directs output to Graph.txt
//Print Headers
exitfile << HEADER1 << endl << HEADER2 << endl << HEADER3 << endl << HEADER4 << endl;
//Print Farm Names
while(enterfile)
{
count = 0;
enterfile.get(FarmName);
while(count <= 30 && FarmName != ‘,’)
{
exitfile << FarmName;
enterfile.get(FarmName);
count++;
}
//Print Blanks and Opening |
while (count < 31)
{
exitfile << ’ ';
count ++;
}
exitfile << “|”;
//Print Stars
enterfile >> acres >> jars;
stars = (jars/acres)/25;
count2 = 1;
while (count2 <= stars)
{
while (count2 == 20)
{
exitfile << “#”;
count2 ++;
}
exitfile << “*”;
count2 ++;
}
//Print Blanks and Closing |
while (count2 < 28)
{
exitfile << ’ ';
count2 ++;
}
exitfile << “|”;
}
cout << DONE << endl << endl << endl;
return 0;
}
Graph.txt
Jessica M Kleiss CSC141-05 | Production in Hundreds |
Project #6 4/1/2002 | Of Pint Jars Per Acre |
| 1 2 3 4 5 6 |
F A R M N A M E |—|---|—|---|—|---|—|
Orville’s Acres |*************** |
Hoffman’s Hills |****************** |
Jiffy Quick Farm |*********** |
Jolly Good Plantation |#** |
Organically Grown Inc. | |
This is the farm that really m|***** |