having some trouble for 2 days now with external files

i have been stuck for 2 days.. I have tried but still no luck. its a project.. its on writing a C++ program that opens the external file, “sales.txt” and reads the data and writes to an external file, “commission.txt”. the external file "commissions.txt" should look like this:
Denver Total sales 500000 Commision 25000
Garry Total sales 1210000 Commision 121000
and the external file "sales.txt" should look like this:
Denver 100000 250000 50000 30000 60000 10000 E Garry 100000 40000 50000 120000 300000 50000 80000 120000 E
the problem I'm having is with the sales.txt. this text file has both numbers and letters and i am having a hard time to display the both on the terminal when the program is executed. instead of displaying whats in the sales.txt file it just displays huge numbers :( please help me

this is the program i wrote:

#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
int salesArray [5];
int num, i,total=0,comm;



ifstream inputfile;
inputfile.open ("sales.txt");

for (i=0; i < 5; i++)
{
inputfile >> num;
salesArray [i] = num;
cout << salesArray[i] << endl;

total=total+num;
if (total > 1000000 )
comm=total*10/100;
else
if(total<1000000 )
comm=total*5/100;
}

ofstream outputfile;
outputfile.open("commissions.txt");
outputfile<<"Denver Total sales "<< total <<" Commission "<< comm<<endl;
outputfile<<"Gary Total sales "<< total <<" Commission "<< comm<<endl;
outputfile<<"Cindy Total sales "<< total <<" Commission "<< comm<<endl;
outputfile<<"Samdaye Total sales "<< total <<" Commission "<< comm<<endl;
outputfile<<"Nalinee Total sales "<< total <<" Commission "<< comm<<endl;



system ("pause");
return 5;
}
this program was executed fine because the sales.txt only contained numbers..
Last edited on
please use code tags. It helps read the code.
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
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
int salesArray [5];
int num, i,total=0,comm;



ifstream inputfile;
inputfile.open ("sales.txt");

for (i=0; i < 5; i++)
{
inputfile >> num;
salesArray [i] = num;
cout << salesArray[i] << endl;

total=total+num;
if (total > 1000000 )
comm=total*10/100;
else
if(total<1000000 )
comm=total*5/100;
} 

ofstream outputfile;
outputfile.open("commissions.txt");
outputfile<<"Denver Total sales "<< total <<" Commission "<< comm<<endl;
outputfile<<"Gary Total sales "<< total <<" Commission "<< comm<<endl;
outputfile<<"Cindy Total sales "<< total <<" Commission "<< comm<<endl;
outputfile<<"Samdaye Total sales "<< total <<" Commission "<< comm<<endl;
outputfile<<"Nalinee Total sales "<< total <<" Commission "<< comm<<endl;



system ("pause");
return 5;
} 
Topic archived. No new replies allowed.