Need help creating this to these instructions, mainly with the part where I call an existing files that has already been created and saved in Notepad as attached.(File one and File two). Below are the directions and some code. I think you will be able to tell what I’m trying to do, Thanks

Requirements:
Create a program to output the following. Make sure it is exact (except for the commission and percentage values):
Commissions calculated using a 0.07 value.
Sales Name Commission

See attachments(2)

This will be accomplished using the following:
1. Read the sales and name values from two input files.
2. Create an array of names and sales amounts (5 total).
3. Determine the commission by randomly generating a percentage number between .05 and. 10. Calculate the commission by multiplying this value times the sales amount.
4. Sort the file by name before printing.
5. Print the file to a third output file. The only thing that should show on the screen is the successful message.
6. Main should have no logic other than calling other functions. All actions should be done in functions (print, read files, sort).

Code:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>

using namespace std;

ofstream OutFile("A:\\File one.out");
ifstream InFile("A:\\File one.in");

const int ARRAY_SIZE = 5;

void PrintArray(double[ARRAY_SIZE][25], int ARRAY_SIZE);
void BubbleSort(double[ARRAY_SIZE][25], int ARRAY_SIZE);
void GetNames(double[ARRAY_SIZE][25], int ARRAY_SIZE);

int main()
{

int arraySales[ARRAY_SIZE][25];
char arrayNames[ARRAY_SIZE][25];

return 0;
}

why are those double and int arrays 2-dimensional??? Arrays must have a name. There are a couple ways you can to it. Leave the array size unspecified and pass the size as another parameter, as in your original attemp.

void PrintArray(double array[], int array_size);
void BubbleSort(double array[], int array_size);
void GetNames(double array[], int array_size);

or just not pass the size as a separate parameter, like this

void PrintArray(double array[ARRAY_SIZE]);
void BubbleSort(double array[ARRAY_SIZE]);
void GetNames(double array[ARRAY_SIZE]);

Isn't the array passed to GetNames() supposed to be an array of strings? Names normally are not arrays of doubles

void GetNames(char array[ARRAY_SIZE][25]);

also

int main()
{
// this is only a 1d array of doubles because each
// salesman has only 1 row in the data file.
double arraySales[ARRAY_SIZE];
// the next array needs to be 2d because it
// is an array of strings
char arrayNames[ARRAY_SIZE][25];

return 0;
}

I had it declared as char originally and thought that was the problem so I changed it to double and that didn't fix it and forgot to change it back. good catch


why are those double and int arrays 2-dimensional??? Arrays must have a name. There are a couple ways you can to it. Leave the array size unspecified and pass the size as another parameter, as in your original attemp.

void PrintArray(double array[], int array_size);
void BubbleSort(double array[], int array_size);
void GetNames(double array[], int array_size);

or just not pass the size as a separate parameter, like this

void PrintArray(double array[ARRAY_SIZE]);
void BubbleSort(double array[ARRAY_SIZE]);
void GetNames(double array[ARRAY_SIZE]);

Isn't the array passed to GetNames() supposed to be an array of strings? Names normally are not arrays of doubles

void GetNames(char array[ARRAY_SIZE][25]);

still can't read files. Next step please.

Arrays must have a name.

Not in a prototype. Onlyt the type of the parameter is needed.

Curtis:
The file must be opened in the execution portion of the code since opening a file is an action. You have it in the declaration portion of the code. Put it in main() Use code tags. It's much faster and easier than coloring your code by hand and preserves the structure -- assuming you have structure. ;)

We got it! Thanks for your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.