Oct 27, 2014 at 4:18am UTC
Hi, most of this code is working, except the part where it's supposed to output the code into the text file. The file remains blank after I test this code. Am I doing something wrong?
The location of the file can be anywhere, you can change that if you want.
-----------------------
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;
void main()
{
double cost;
double salary;
double rent;
double electricity;
int netprofit;
int x;
int mark;
int marka;
ifstream infile;
ofstream outfile;
infile.open("C:\\Users\WHIT216\\Documents\\Visual Studio 2013\\Projects\\Win32Project1\\Win32Project1\\File2.txt");
outfile.open("C:\\Users\WHIT216\\Documents\\Visual Studio 2013\\Projects\\Win32Project1\\Win32Project1\\File2.txt");
//outfile << "Enter total cost of merchandise: " << endl;
infile >> cost;
//outfile << "Enter salary of employees: " << endl;
infile >> salary;
//cout << "Enter rent: " << endl;
infile >> rent;
//cout << "Enter Electric bill: " << endl;
infile >> electricity;
x = (cost + salary + rent + electricity);
mark = (100 * x * 1.1) / 85;
marka = mark * .15 + mark;
outfile << "Store Rent: " << std::right << std::setw(24) << setfill('.') << "$" << rent << std::endl;
outfile << "Salary: " << std::right << std::setw(28) << setfill('.') << "$" << salary << std::endl;
outfile << "Electricity: " << std::right << std::setw(23) << setfill('.') << "$" << electricity << std::endl;
outfile << "Merchandise Cost: " << std::right << std::setw(18) << setfill('.') << "$" << cost << std::endl;
outfile << "Net Profit: " << std::right << std::setw(26) << setfill('.') << "10%" << std::endl;
outfile << "Merchandise Price: " << std::right << std::setw(17) << setfill('.') << "$" << mark << std::endl;
outfile << "Merchandise 15% Sale Price: " << std::right << std::setw(8) << setfill('.') << "$" << marka << std::endl;
//cout << "Your net profit is " << (100 * x*1.1) / 85 << endl; system("Pause");
system("Pause");
infile.close();
outfile.close();
}
Oct 27, 2014 at 7:35pm UTC
marka = mark * .15 + mark;
You're taking 15% of mark and adding it to the original value of mark, so you end up with a higher figure.
You'd want to end up subtracting the discount from the regular price.
Sales price = regular price - discount