I am at the end of my first term in my C++ classes. I have managed well so far, but this program is completely frustrating me! Please help me figure what to do.
Okay my assignment is kind of complicated for me.....here is what I am supposed to do, followed by the code that I have so far. I know that I still have quite a bit to do, but I am completely stuck at this point, with no clue how to get to where I want to be.
My program should output:
Commissions are calculated using a 0.07 value.
Sales Name Commission
2000.98 Abbott, Sue 140.07
950.12 Green, John 66.51
875.50 Jones, Mary 61.29
etc...
I am supposed to read the info from two input files (sales in one, and names in two) then create arrays for each. Determine commission randomly by generating percentage between .05 and .10 (Is there a way that I could .10 to print like that? In my current code it always reads as .1). Then I need to calculate the commission using sales and the generated number. I'm baffled by this, since I can't just multiply the numbers, I think I need to convert them, but am unsure how. My other BIG problem is how can I get the format to print the Sales, Name, and Commission on each line? There is a couple other things like sorting and printing to output file, but I'm pretty sure I can do that.
//
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <sstream>
using namespace std;
void Print();
void ReadSales();
void ReadNames();
float getrand();
int main()
{
Print();
ReadSales();
ReadNames();
system("pause");
return 0;
}
void ReadSales()
{ char sales [5][15];
ifstream myfile("File one.txt");
if(myfile.is_open())
{
while(!myfile.eof())
{
for (int i = 0; i < 4 ; i++)
{
myfile.get(sales[i],8,'\0');
cout << sales[i];
}
}
cout << endl;
}
else cout << "Unable to load file!" << endl;
}
void ReadNames()
{
char name [5][15];
ifstream myfile2("File two.txt");
if(myfile2.is_open())
{
while(!myfile2.eof())
{
int sizeOfFile = 0;
for (int j = 0; j < 4 ; j++)
{
myfile2.get(name[j],15,'\0');
sizeOfFile++;
}
for (int j = 0; j < sizeOfFile; j++)
{
cout << name[j];
}
}
cout << endl;
}
else cout << "Unable to load file!" << endl;
}
void Print()
{
cout << "Commissions calculated using a " << getrand() << " value." << endl << endl;
cout << "Sales" << setw(16) << "Name" << setw(32) << "Commission" << endl << endl;
}
float getrand()
{
srand(unsigned(time(0)));
float commission = (rand() % 6 + 5.0)/100;
return commission;
}