OK heres my second question of the day. I am trying to output my information to the screen and to a file called billing.dat. I have perused the board and I just don't understand the FAQ or other users explaination of how to do it. I do know I have to include fstream (which I did) but from there I am completely lost. I have included my sample code...I don't want it done for me just a laymans explaination of how to output my information to a file. I am a newbie after all =/
Code:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
const double RED_RUG = 4.99;
const double GREEN_RUG = 5.99;
const double BLUE_RUG = 6.99;
int main()
{
char filename[15];
string discount;
char customerName[25];
char rugColor;
char paymentMethod;
int roomLength;
int roomWidth; //variables
string rugDisplay;
string discountPercent;
int roomArea;
double endDiscount;
double paidDiscount;
double rugCost;
double carpetCost;
double trueCost;
cout<<setiosflags(ios::fixed);
cout<<"Enter file name for billing: ";
cin.getline(filename,15);
cout<<setw(20)<<"Welcome to..."<<endl;
cout<<endl;
cout<<setw(40)<<">>>Phils Floors<<<<"<<endl; //business header-output to screen
cout<<endl;
cout<<setw(36)<<"Our Rugs Rock"<<endl;
cout<<endl;
cout<<"If you enter the customers name, type of rug purchased,"<<endl;
cout<<"room dimensions, and type of payment, this program"<<endl; //program explaination
cout<<"will calculate and print a bill to a file, Billing.dat"<<endl;
cout<<endl;
cout<<"Please enter the customers name: ";
cin.getline(customerName,25); //input customers name
cout<<endl;
cout<<"Please enter rug color (R)ed (B)lue (G)reen: ";
cin>>rugColor; //input rug color
cout<<endl;
if (rugColor == 'R' || rugColor == 'r')
{
rugDisplay = "RED";
rugCost = RED_RUG;
}
else
if (rugColor == 'B' || rugColor == 'b')
{
rugDisplay = "BLUE"; //set rugdisplay variable and cost of rug
rugCost = BLUE_RUG;
}
else
if(rugColor == 'G' || rugColor == 'g')
{
rugDisplay = "GREEN";
rugCost = GREEN_RUG;
}
else
{
rugDisplay = "Default";
rugCost = 6.99;
}
cout<<"Please enter the method of payment"<<endl;
cout<<"(C)ash (Z)ippy or (O)ther: ";
cin>>paymentMethod; //input payment method
cout<<endl;
if (paymentMethod == 'C' || paymentMethod == 'c')
{
paidDiscount = .10;
}
else if (paymentMethod == 'Z' || paymentMethod == 'z') //set paidDiscount variable to use in calculation
{
paidDiscount = .05;
}
else
{
paidDiscount = 1;
}
if (paymentMethod == 'C' || paymentMethod == 'c')
{
discount = "Cash and Carry";
discountPercent = "10% -- Cash and Carry";
}
else if (paymentMethod == 'Z' || paymentMethod == 'z')
{
discount = "Zippy Discount"; //set discount variables (output messages)
discountPercent = "5% -- Zippy Discount";
}
else if (paymentMethod == 'O' || paymentMethod == 'o')
{
discount = "No Discount";
discountPercent = "No Discount";
}
else
{
discount = "No payment type specified";
discountPercent = "No Discount";
}
cout<<"Enter the Length of your room: "; //input room length
cin>>roomLength;
cout<<endl;
cout<<"Enter the Width of your room: ";
cin>>roomWidth; //input room width
cout<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
roomArea = roomWidth * roomLength; //calculate room area
carpetCost = roomArea * rugCost; //calculate rug cost
endDiscount = roomArea * rugCost * paidDiscount; //calculate discount
trueCost = carpetCost - endDiscount; //calculate carpet cost minus the discount (truecost)
if (paidDiscount == 1)
{
trueCost = carpetCost; //set no discount variables
endDiscount = 0;
}
cout<<setw(40)<<">>>Phil's Floors<<<<"<<endl;
cout<<endl; //output header
cout<<setw(36)<<"Our Rugs Rock"<<endl;
cout<<endl;
cout<<"Customer Name:"<<setw(27)<<customerName<<endl; //output customer name
cout<<endl;
cout<<"Rug Color:"<<setw(31)<<rugDisplay<<endl; //output rugcolor
cout<<endl;
cout<<"Payment Method:"<<setw(26)<<discount<<endl; //output payment method
cout<<endl;
cout<<setw(30)<<discountPercent<<endl; //output discount percent message
cout<<endl;
cout<<setprecision(2)<<"Discount: "<<setw(26)<<"$"<<endDiscount<<endl; //output discount
cout<<endl;
cout<<setprecision(2)<<"Rug Cost: "<<setw(25)<<"$"<<carpetCost<<endl; //output carpet cost (before discount)
cout<<endl;
cout<<setprecision(2)<<"Final Cost:"<<setw(24)<<"$"<<trueCost<<endl; //output carpet cost(final cost-after discount)
cout<<endl;
return 0;
}