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;
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..