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

I didn't really read your code as I am in a hurry.
this might be long and consume a lot of memory but you sho;uld try it anyway: why don't you take input from a file and store it into two parallel arrays. After storing that information I think you should use the random function to generate a number and use that number to point to whatever index will be displayed.

If this is not helpful sorry it's all i've got since you didn't highlight the keypoints and I don't have a lot of time.
goodluck

Sorry this is what I was having trouble with:

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?

I still need to create a third array that uses sales array and rand commission and since thier not same type I don't know how to convert. Then I think I need to combine my arrays somehow, possibly concat in order to get my final out put of columns.

I've spent a lot of hours trying to figure this out and just looking for some guidance.

I understand that I can, but I don't understand how.....
When I try, I keep getting errors saying: cannot convert `char (*)[50]' to `const char*' for argument `1' to `double strtod(const char*, char**)' or something similar to that.

k
The rest I still have to think about but for outputing

cout<<"commision\t"<<"blah\t"<<"blah"<<endl;
for(int n=0;n<blah;n++)
{
cout<<commision<<"\t"<<blah<<"\t"<<blah<<endl;
}

NB blah stands for what ever other data you need to output

This article has been dead for over six months. Start a new discussion instead.