Trouble creating a dat file to declare variable values

Im writing a program that calculates cost of making cylinders. The variables used are inputted which work when ran, but 2 variables i am required to use a dat file to input 2 variable values. I am confused on how i create the file and what the dat file will look like just so that i can input that file to declare variables in my program.


#include <iostream> // cout and cin definitions
#include <iomanip> // set precision, showpoint, and fixed definitions
#include <fstream>
using namespace std;

double radius_of_base; // Radius of the base of the cylinder
double height; // Height of the cylinder
double cost; // Cost per square centimeter of material
int quantity; // How many containers
double SA; // Surface Area
double costContainer; // Cost to make one container
double costALL; // Cost to make stated quantity of containers
const float pi = 3.14; // The constant Pi
ifstream infile; // Load file INLABIV.DAT

void Documentation(); // Stating our functions
void User_Input();
void File_Input();
void Calculations();
void Output();

int main() // Main which includes the functions
{
Documentation();
User_Input();
File_Input();
Calculations();
Output();
return 0;
}
// Pre-Conditions: None
// Post-Conditions: Descirption of program outputted

void Documentation() // Outputs description of program
{
cout << "A manufacturer wants to determine the cost of producing an open top\ncylindcrical container. ";
cout << "The surface area is equal to the sum of the area of the base plus the area ";
cout << "of the outside of the cylindrical container which is the\ncircumfrence of the base times the height. " << endl;
}

//Pre Conditions: Program description outputted
//Post Conditions: Height and radius outputted

void User_Input()
{
cout << "Enter the radius of the base: " << endl;
cin >> radius_of_base;
cout << "Enter the height: " << endl;
cin >> height;
}
//Pre Conditions: Radius and height inputted
//Post Conditions: Cost and quantity values inputted

void File_Input()
{
infile.open("INLABIV.DAT");

infile >> cost >> quantity;
}
//Pre Conditions: Cost and quantity values inputted
//Post Conditions: Cost per cyliner, total cost, and surface area calculated

void Calculations() // Function which states our equations and the variables to complete them
{
SA = 2 * pi * radius_of_base * height + 2 * pi * radius_of_base * radius_of_base;
costContainer = SA * cost;
costALL = costContainer * quantity;
}
//Pre Conditions: Surface area, cost per container, and total cost are calculated.
//Post Conditions: Height, radius, cost per cm, quantity, and cost per cylinder are outputted

void Output() // Function which outputs the stated variables as well as cost per container and cost for all containers
{
cout << fixed; // When using 'fixed' outputs a fixed decimal point
cout << fixed << setprecision(4) << "The radius is equal to " << radius_of_base << endl; // States value of radius
cout << fixed << setprecision(4) << "The height is equal to " << height << endl; // States value of height
cout << "The number of cylinders being manufactured is " << quantity << endl; // States quantity of cylinders being produced
cout << fixed << setprecision(2) << "The cost per square centimeter of material is $" << cost << endl; // States the ost per square centimeter of material
cout << "The cost to make one cylinder at $" << fixed << setprecision(2) << cost << " per square centimeter is $" << fixed << setprecision(2) << costContainer << " each." << endl;
cout << "The total cost to manufacture " << quantity << " containers is $" << fixed << setprecision(2) << costALL << endl; // Outputs cost to make all the cylinders
}
If your making the dat file you can put the 2 values on the same line or on different lines.

If not then you need to know the format so you can pick out the values.
so to create the file do i just add new item and save as .dat and then it would just be

1.45
30

if those were the values i needed to put in?
because right now the program runs the values are just 0 when i run it
Topic archived. No new replies allowed.