Need help with this code

Oct 27, 2014 at 4:18am
closed account (92w05Di1)
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 4:43am
please use code tags..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#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();
} 


line 19 and 20: Users\WHIT216 --> Users\\WHIT216
Oct 27, 2014 at 5:16pm
closed account (92w05Di1)
ALright, that did the trick :P

But one more thing, my professor sent me an email asking
"Why is sales price bigger than markup price (sales price is 85% of markup price, not 115%)?"


I don't know what I am supposed to do to fix that.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#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\\Mike2\\Desktop\\File1.txt");
outfile.open("C:\\Users\\Mike2\\Desktop\\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
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
Topic archived. No new replies allowed.