What up yall, Im working on this program that reads in strings and numbers from text file and store them into an parallel arrays.

My program also needs to:
"list each sales person ID,name,sales amount, and commissions"
"list each month of the year and total sales for the month for all sales people"
"list total sales and total commissions earned by all sales people"

Ok so i figured out the first part, im reading into the arrays from the files and i display the information to the screen and i also figured out the function to calculate the commissions and display them to the screen.

Now is where my main problem comes in, i cant figure out the total sales amount for the month of the year and i cant figure out the total sales and total commission earned by all sales people

// Array.cpp : main project file.

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <fstream>


using namespace std;

double calculate_commission(double commission,double saleamount);
double calculate_totalsaleamount(double totalsaleamount,double saleamount,int time);
double calculate_totalcommission(double totalcommission,double commission,int time);
double calculate_totalsaleformonth(double totalsaleformonth,double saleamount,int month);

int main()
{
   //DECLARE ARRAYS
   string salespersonName[12];
   int salespersonID[12];
   int month[12];
   int day[12];
   int year[12];
   int time[7];
   string timeframe[4];
   string monthstring[12];
   int monthdigits[12];
   double saleamount[12];
   double commission[4];
   double totalcommission[4];
   double totalsaleamount[4];
   double totalsaleformonth[12];

 
//-------------------------------------------------------------------------------------------------------------
   
   //READ FROM TEXT FILE TO ARRAYS
   
   //READ IN NAMES
   
   short loop = 0; //short for loop for input

   string line; // this will contain the data read from the file

   ifstream myfile;
   
   myfile.open("Names.txt",ios::in); // open the file.

   if(myfile.is_open()) // if the file is open
   {
	   while(! myfile.eof()) // while the end of file is NOT reached
	   {
		   getline (myfile,line); // get one line from the file
		   salespersonName[loop] = line;
		   loop++;
	   }
	   myfile.close(); //closing the file
   }
   else cout << "Unable to open file"; //if the file is not open output

  //READ IN ID
   
   ifstream myfile2;

   myfile2.open("ID.txt",ios::in);

   for(loop=0;loop<12;loop++)
   {
	   myfile2 >> salespersonID[loop]; //get number from file
   }

   myfile2.close();

  //READ IN MONTH
  
   ifstream myfile3;

   myfile3.open("Month.txt",ios::in);

   for(loop=0;loop<12;loop++)
   {
	   myfile3 >> month[loop]; //get number from file
   }

   myfile3.close();

   //READ IN DAY
  
   ifstream myfile4;

   myfile4.open("Day.txt",ios::in);

   for(loop=0;loop<12;loop++)
   {
	   myfile4 >> day[loop]; //get number from file
   }

   myfile4.close();

  //READ IN YEAR
   
   ifstream myfile5;

   myfile5.open("Year.txt",ios::in);

   for(loop=0;loop<12;loop++)
   {
	   myfile5 >> year[loop]; //get number from file
   }

   myfile5.close();

  //READ IN TIME

   ifstream myfile6;

   myfile6.open("Time.txt",ios::in);

   for(loop=0;loop<12;loop++)
   {
	   myfile6 >> time[loop]; //get number from file
   }

   myfile6.close();

  //READ IN SALE AMOUNT
   
   ifstream myfile7;

   myfile7.open("SaleAmount.txt",ios::in);

   for(loop=0;loop<12;loop++)
   {
	   myfile7 >> saleamount[loop]; //get number from file
   }

   myfile7.close();

   
   //READ IN TIME FRAME
  
   short loop1 = 0; //short for loop for input

   string line1; // this will contain the data read from the file

   ifstream my;
   
   my.open("TimeFrame.txt",ios::in); // open the file.

   if(my.is_open()) // if the file is open
   {
	   while(! my.eof()) // while the end of file is NOT reached
	   {
		   getline (my,line1); // get one line from the file
		   timeframe[loop1] = line1;
		   loop1++;
	   }
	   my.close(); //closing the file
   }
   else cout << "Unable to open file"; //if the file is not open output

   //READ IN MONTH DIGITS

   ifstream myfile8;

   myfile8.open("MonthDigits.txt",ios::in);

   for(loop=0;loop<12;loop++)
   {
	   myfile8 >> monthdigits[loop]; //get number from file
   }

   myfile8.close();

   //READ IN MONTH STRINGS

   short loop2 = 0; //short for loop for input

   string line2; // this will contain the data read from the file

   ifstream my2;
   
   my2.open("MonthString.txt",ios::in); // open the file.

   if(my2.is_open()) // if the file is open
   {
	   while(! my2.eof()) // while the end of file is NOT reached
	   {
		   getline (my2,line2); // get one line from the file
		   monthstring[loop2] = line2;
		   loop2++;
	   }
	   my2.close(); //closing the file
   }
   else cout << "Unable to open file"; //if the file is not open output


   
//-----------------------------------------------------------------------------------------------------------------

	//BEGIN TO OUTPUT TEXT AND GET RESPONSE
   
   char response1;

	cout << "Enter a to list each sales person ID,name,sales amount, and comissions" << endl;
	cout << "Enter b to list each month of the year and total sales for the month for all sales people" << endl;
	cout << "Enter c to list total sales and total commissions earned by all sales people" << endl;
	cout << "Enter x to exit" << endl;
	cin >> response1;
	
	while (response1 != 'x')
	{
	switch(response1)
	{
	case 'a':
	cout << endl;
	cout << "SALE PERSON ID" << "   " << "SALE PERSON NAME" << "   " << "SALE AMMOUNT" << "   " << "COMMISSION" << endl;
	for(int loop=0;loop<12;loop++)
	{
		cout <<"    " << salespersonID[loop] << "               " << salespersonName[loop] << "        " << saleamount[loop] << "          " <<  calculate_commission(commission[loop], saleamount[loop]) << endl;
	}
	break;
	case 'b':
	cout << endl;
	cout << "MONTH OF THE YEAR" << "      " << "TOTAL SALES FOR MONTH FOR ALL SALES PEOPLE" << endl;
	for(int loop=0;loop<12;loop++)
	{
		cout << "   " << monthdigits[loop] << "  " << monthstring[loop] << "                     " << calculate_totalsaleformonth(totalsaleformonth[loop],saleamount[loop],month[loop]) << endl;
	}
	break;
	case 'c':
	cout << endl;
	cout << "   " << "TIME FRAME" << "        " << "TOTAL SALES" << "        " << "TOTAL COMMISSIONS" << endl;
	for(int loop=0;loop<4;loop++)
	{
		cout << " " << timeframe[loop] << "         " << calculate_totalsaleamount(totalsaleamount[loop],saleamount[loop],time[loop]) << "           " << calculate_totalcommission(totalcommission[loop],commission[loop],time[loop]) << endl;
	}
	break;
	default:
		cout << "Illegal entry \n;";
	break;
	}
	
	cout << endl;
	cout << "Enter a to list each sales person ID,name,sales amount, and comissions" << endl;
	cout << "Enter b to list each month of the year and total sales for the month for all sales people" << endl;
	cout << "Enter c to list total sales and total commissions earned by all sales people" << endl;
	cout << "Enter x to exit" << endl;
	cin >> response1;
	}
   return 0;

}
//-------------------------------------------------------------------------------------------------------------

// COMMISSION FUNCTION

double calculate_commission(double commission,double saleamount)
{
	if (saleamount <= 50000)
	{
		commission = saleamount * .04;
	}
	else
	{
		if (saleamount >= 50001 && saleamount <=125000)
		{
			commission = saleamount * .05;
		}
		else
		{
			if (saleamount >= 125001 && saleamount <= 200000)
			{
				commission = saleamount * .06;
			}
			else
			{
				if (saleamount >= 200001)
				{
					commission = saleamount * .07;
				}
			}
		}
	}
	return commission;
}

// TIME FRAME SALES FUNCTION

double calculate_totalsaleamount(double totalsaleamount,double saleamount,int time)
{
	if(time <= 559)
	{
		totalsaleamount = totalsaleamount + saleamount;
	}
	else
	{
		if (time >= 600 && time <= 1259)
		{
			totalsaleamount = totalsaleamount + saleamount;
		}
		else
		{
			if(time >= 1300 && time <= 1759)
			{
				totalsaleamount = totalsaleamount + saleamount;
			}
			else
			{
				if (time >=1800 && time <= 2359)
				{
					totalsaleamount = totalsaleamount + saleamount;
				}
			}
		}
	}
	return totalsaleamount;
}



// TIME FRAME COMMISSION FUNCTION

double calculate_totalcommission(double totalcommission,double commission,int time)
{
	if(time <= 559)
	{
		totalcommission = totalcommission + commission;
	}
	else
	{
		if (time >= 600 && time <= 1259)
		{
			totalcommission = totalcommission + commission;
		}
		else
		{
			if(time >= 1300 && time <= 1759)
			{
				totalcommission = totalcommission + commission;
			}
			else
			{
				if (time >=1800 && time <= 2359)
				{
					totalcommission = totalcommission + commission;
				}
			}
		}
	}
	return totalcommission;
}

//TOTAL SALE OF THE MONTH FUNCTION

double calculate_totalsaleformonth(double totalsaleformonth,double saleamount,int month)
{
	if( month = 1)
	{
		totalsaleformonth = totalsaleformonth + saleamount;
	}
	else
	{
		if (month = 2)
		{
			totalsaleformonth = totalsaleformonth + saleamount;
		}
		else
		{
			if (month = 3)
			{
				totalsaleformonth = totalsaleformonth + saleamount;
			}
			else
			{
				if (month = 4)
				{
					totalsaleformonth = totalsaleformonth + saleamount;
				}
				else
				{
					if (month = 5)
					{
						totalsaleformonth = totalsaleformonth + saleamount;
					}
					else
					{
						if (month = 6)
						{
							totalsaleformonth = totalsaleformonth + saleamount;
						}
						else
						{
							if (month = 7)
							{
								totalsaleformonth = totalsaleformonth + saleamount;
							}
							else
							{
								if (month = 8)
								{
									totalsaleformonth = totalsaleformonth + saleamount;
								}
								else
								{
									if (month = 9)
									{
										totalsaleformonth = totalsaleformonth + saleamount;
									}
									else
									{
										if (month = 10)
										{
											totalsaleformonth = totalsaleformonth + saleamount;
										}
										else
										{
											if (month = 11)
											{
												totalsaleformonth = totalsaleformonth + saleamount;
											}
											else
											{
												if (month = 12)
												{
													totalsaleformonth = totalsaleformonth + saleamount;
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	return totalsaleformonth;
}

First, unwind that excessive indentation.
12 closing } in a row is just awful.

This is how you should do an if / else if / else chain

if ( cond ) {
}
else if ( cond ) {
}
else if ( cond ) {
}
else {
}

> if (month = 12)
Use == for COMPARISON.

A good compiler should be able to tell you if you're using assignment where a comparison is more usual.

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.