Thread: My Arrays!!!, My Arrays!!! Help!?

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    5

    My Arrays!!!, My Arrays!!! Help!?

    Yeah so I'm Using Some Arrays, and Functions and Such, the only problem is that my output is getting scrambled up, my commission array is the only fine one I believe. I do not know what is wrong, because each time I print the data, I'm guessing I'm getting some kind of infinite loop, that is trying compute some undefine arrays. I just don't know right now, I'm lost could you help? If any of you could run it and find the problem, that would be swell, ya know. I'm looking for positive input, oh my agent ID, it was weird defined as a integer, it goes through a function validation loop, and then the function requests for a cin, once again , i believed I pass the array, but for some reason the output retains the original bad data. My agent id should be 5 digits long

    Code:
    //Put in Those SetW's
    /**************************************************
    **	  Daniel Lopez	  |		November 3rd, 2006   **
    **  -------------------------------------------  **
    **|||||||||||||| estate_comm.cpp ||||||||||||||  **
    ***************************************************
    ** Input: choice, agent_id, yesno, prop_sell     **
    ***************************************************
    ** Output: num_prop1 ,num_prop2 ,num_prop3,      **
    ** prop_price_r, prop_price_c, prop_price_m      **
    ** prop_price									 **
    ***************************************************
    ** Program Purpose:								 **
    **		The program's purpose is to implement	 **
    ** several functions that perform such duties	 **
    ** such as: printing a dashline, or the total of **
    ** of a commission, also functions are used to	 **
    ** validate data.								 **
    **************************************************/
    
    #include <iostream>
    #include <iomanip>
    		using namespace std;
    //Function Prototypes Declaration
    /*-------------------------------------------------------------------------------*/
    		
    		void DashLine(void);									//Print Dashed Line
    		double CompComm(double, double);						//Compute Commission
    		void PrintComm(double, double, double);					//Print Maximum,Mininum,Average
    		int ValAgentId(int);									//Validation Function: Agent ID
    		char ValPropType(char);									//Validation Function: Property Type
    		double ValComm(double);									//Validation Function: Commission = +
    		char ValYesNo(char);									//Validation Function: Compute Another Commission?
    
    /*-------------------------------------------------------------------------------*/
    //CONSTANT DEFINE (PROPERTY_TYPE),
    #define PROP_R 0.1					//10%
    #define PROP_C 0.2					//20%
    #define PROP_M 0.15					//15%
    #define COMP_NAME "Pleasantville Estates"
    #define DYWEEK "Friday"
    #define NAME "Daniel Lopez Commission Computer"
    #define AGENTLO 10000				//Lower Bounds
    #define AGENTHI 100000				//Upper Bounds
    #define NOTHING 0					//Nada
    #define SIZE 50						//Array Size
    
    //Program Body
    int main ()
    //Compute Commission Definition Function
    
    	
    
    {
    	char   choice[SIZE],				/*Switch Case R,C,M*/
    		   yesno,				/*Another Commission???*/
    		   valid_choice;		/**/
    	int	   agent_id[SIZE],			/* Five Digit ID */
    		   num_prop1,			/*Quantity of Properties*/
    		   num_prop2,
    		   num_prop3;
    	int	   whileyesno;
                       double val_sell_pricee,
    		   prop_price_r,		/*Propety Selling Prices*/
    		   prop_price_c,
    		   prop_price_m,
       	          prop_sell[SIZE],			/*Propety Selling Price Total*/
    		   comm_r,				/*Commission Property Sales*/
    		   comm_c,
    		   comm_m;
    	//Update_1 Variables
    	double commission[SIZE]={0} ,
    		   maximum,				/*Commission Maximum, Mininum, Average*/
    		   minimum,
    		   average,
    		   total,				/*Commission[j] Accumilative Total*/
    		   counter;				/* double counter converted from int k*/
    	int	   j=0,					/*For PreIncrement*/
    		   k=0;					/*Commission Tally*/
    	
    	//Update_2 Variable - Sorting Arrays
    	double temp;
    	int	row,
    		exm=1,
    		last;
    	//Initializing Variables
    		
    	  //  commission[k]={0} Initalizes Each Element of the Array as 'zero'
    		num_prop1 = 0;
    		num_prop2 = 0;
    		num_prop3 = 0;
    		comm_r = 0;
    		comm_c = 0;
    		comm_m = 0;
    		total = 0.0;
    	
    	//CONSTANT/Variable Declaration/Initalization
    	//Display Banner and Agent ID Request
    	cout << "------------------------" << NAME << "------------------------\n\n" ;
    	cout << COMP_NAME << "                                                 " << DYWEEK;
    	cout << "\n"
    		 << "\n--    Agent's Real Estate Sales Commission Report   --";
    	cout << "\n----------------------------------------------------------";
    	cout << "\n\nDo you have a commission to compute? ( 1 - Yes // 0 - No ) >> ";
    	//Validate Yes Or No
    	
    	cin  >> yesno;
    	while ((yesno != '0' && yesno != '1')){
    	cout << "Yes or NO!						      ";
    	cin  >> yesno;
    	}//endwhile
    	
    	if (yesno == '1')
    	{
    	do
    	{	
    		cout << "\n\nEnter Your Five Digit Agent ID#(_____): ";	
    	//Validate Agent's ID		
    		int xx=0;
    		cin >> agent_id[xx];
    		int valid;
    		valid =ValAgentId(agent_id[xx]);
    		if (valid==1) 
    			cout << valid;
    		//endwhile
    	/*
    	---------------------------------------------------------------------
        */
    	// Property Category Display
    	cout << "\nProperty Types:"<<endl;
    	cout << "---------------\n";
    	cout << "\tR - Residential"<<endl
    		 << "\tC - Commercial"<<endl
    		 << "\tM - Multiunit Dwelling"<<endl;
    	//endDisplay
    	
    	
    	//Property Category Selection 
    	cout << "\nChoice: ";
    	int zz=0;
    	cin >> choice[zz];
    	valid_choice =ValPropType(choice[zz]);
    	zz++;
    	cout << "\n\nEnter Selling Price:\t\t\t\t$ ";
    	//Validating Property Selling Price
    	int yy=0;
    	cin >> prop_sell[yy];
    	val_sell_pricee =ValComm(prop_sell[yy]);
    	prop_sell[yy]+= val_sell_pricee;
    	yy++;
    		
    	//Request Selling Price, and Computing/Displaying Commission
    	switch (valid_choice)
    	{
    		case 'R': 
    		case 'r': 
    				prop_price_r = CompComm(val_sell_pricee, PROP_R);			//Calculation
    					comm_r+= prop_price_r;					//Residential Price Accumulator
    						num_prop1++;						//Residential Number Accumulator
    						cout << "\n"<<"Sales Agent ( " <<agent_id[xx]<<" )"
    					    	 << "\n---------------------\n"
    							 << "Commission Made:\t\t\t\t$ "<< fixed << setprecision(2) << prop_price_r;
    								//Array Commission
    								commission[k]+= prop_price_r;
    									k++;
    										xx++;
    										break;
    		case 'C': 
    		case 'c': 
    				prop_price_c = CompComm(val_sell_pricee, PROP_C);			//Calculation
    					comm_c+= prop_price_c;					//Commercial Price Accumulator
    						num_prop2++;						//Commercial Number Accumulator
    						cout << "\n"<<"Sales Agent ( " <<agent_id[xx]<<" )"
    							 << "\n---------------------\n"
    							 << "Commission Made:\t\t\t\t$ "<< fixed << setprecision(2) << prop_price_c;
    								//Array Commission
    								commission[k]+= prop_price_c;
    									k++;
    										xx++;
    										break;
    		case 'M': 
    		case 'm': 
    				prop_price_m = CompComm(val_sell_pricee, PROP_M);			//Calculation
    					comm_m+= prop_price_m;					//Mult Price Accumulator
    						num_prop3++;						//Mult Number Accumulator
    						cout << "\n"<<"Sales Agent ( " <<agent_id[xx]<<" )"
    							 << "\n---------------------\n"
    							 << "Commission Made:\t\t\t\t$ "<< fixed << setprecision(2) << prop_price_m;
    								//Array Commission
    								commission[k]+= prop_price_m;
    									k++;
    										xx++;
    										break;
    		}
    	//end_switch
    	cout << "\n\nDo you have another commission to compute? ( 1 - Yes // 0 - No ) >> ";
    	cin  >> yesno;
    	
    	whileyesno =ValYesNo(yesno);		
    			
    	}
    	while (whileyesno=='1');
    	//End Big Ass While
    	
    			cout << "\n\n********************* End of Run Report *********************\n\n";
    	//Display Running Report
    	// Display Total Tally
    cout << " Total Number of Residential Commissions Computed:      "<< setw(2)<<num_prop1<<endl;
    		cout << " Total Number of Commercial Commissions Computed:       "<< setw(2)<<num_prop2<<endl;
    		cout << " Total Number of Multiunit Commissions Computed:        "<< setw(2)<< num_prop3<<endl;
    		cout << " Total Number of ALL Commissions Computed:              "<< setw(2)<<num_prop1 + num_prop2 + num_prop3<<endl;
    	// 
    DashLine();//DashLine Function
    			
    			//Display Total Amount
    			cout << " Total Amount of Residential Commissions Computed:  $"<< setw(10)<<comm_r<<endl;
    			cout << " Total Amount of Commercial Commissions Computed:   $"<< setw(10)<<comm_c<<endl;
    			cout << " Total Amount of Multiunit Commissions Computed:    $"<< setw(10)<< comm_m<<endl;
    			cout << " Total Amount of ALL Commissions Computed:          $"<< setw(10)<<comm_r + comm_c + comm_m<<endl;
    
    //Calculating Commission's Maximum, Minimum, Average
    	maximum = commission[0];
    	minimum = commission[0];
    	average = 0;
    	counter = k;
    	for (j=0 ; j < counter ; j++)
    	{
    		if (maximum  < commission[j])
    			maximum = commission[j];//endif
    		if (minimum > commission[j])
    			minimum = commission[j];//endif
    		
    		total += commission[j];
    	}//endfor
    	if (counter > 0){ 
    			average = total/counter;}
    	else{//when count == 0;
    		average = -1;}
    		
    	DashLine();
    	PrintComm(maximum,minimum,average);
    	
    	DashLine();
    	cout << " Commission Report" << endl;
    	DashLine();
    	
    	do{
    		exm =0;
    		last= k-1;
    		for (row =0; row < last; row++)
    	{
    			if ( commission[row] > commission[row+1] )
    			{
    				temp = commission[row];
    				commission[row] = commission[row+1];
    				commission[row+1] = temp;
    				//Agent ID Sort
    				int temp_ai;
    				temp_ai = agent_id[row];
    				agent_id[row] = agent_id[row+1];
    				agent_id[row+1] = temp_ai;
    				double temp_ps;
    				temp_ps = prop_sell[row];
    				prop_sell[row] = prop_sell[row+1];
    				prop_sell[row+1] = temp_ps;
    				char temp_ch;
    				temp_ch = choice[row];
    				choice[row] = choice[row+1];
    				choice[row+1] = temp_ch;
    				exm=1;
    			}//endif
    		}//endfor
    		last--;
    	}while (( last > 0 ) && (exm==1));//enddo
    
    			for (j=0 ; j < counter ; j++){
    			cout 
    				<<"agent id:" << agent_id[j]<<endl
    				<<"choice: "<< choice[j]<<endl
    				<<"prop_sell:" << prop_sell[j]<<endl
    					<<"commission: "<< commission[j]<<endl ;
    			}//endfor
    }
    
    
    	return 0;
    }
    // Functions Definitions
    /**********************************************************************************
    ** Function CallName: DashLine()
    ** Return Type: void, thus none.
    ** Input: None
    ** Output: "...----..."
    ** Purpose: To print a Dashed Line
    **********************************************************************************/
    
    void DashLine(void)	{
    			cout << "\n\n   --------------------------------------------------------\n\n\n";
    		}
    
    /**********************************************************************************
    ** Function Call Name: CompComm()
    ** Return Type: double
    ** Input: double prop_sell, double PROP_RATE
    ** Output: Commission of Various Property Types
    ** Purpose: Multiply Selling Price * Constant of Propety Type
    **********************************************************************************/
    double CompComm(double price, double rate){
    	return (price * rate);
    }
    
    /**********************************************************************************
    ** Function Call Name: PrintComm()
    ** Return Type: double
    ** Input: double
    ** Output: Maximum, Mininum, Average
    ** Purpose: To Print Maximum, Mininum, Average
    **********************************************************************************/
    void PrintComm(double maximum, double minimum, double average){
    	cout << " Maximum Commission:                                $"<< fixed << setprecision(2) << setw(10) << maximum << endl;
    	cout << " Minimum Commission:                                $"<< fixed << setprecision(2) << setw(10) << minimum << endl;
    	cout << " Average Commission:                                $"<< fixed << setprecision(2) << setw(10) << average << endl;
    }
    
    /*********************************************************************************
    ** Function Call Name: ValAgentId()
    ** Return Type: int
    ** Input: none
    ** Output: Validation T/F
    ** Purpose: To validate AgentID Loop
    *********************************************************************************/
    int ValAgentId(int val_agent_id){
    	
    	while (!(val_agent_id >= AGENTLO && val_agent_id < AGENTHI)){
    		cout << "Five Digits Please: ";
    		cin  >> val_agent_id;		
    		}
    	return val_agent_id;
    }
    /*********************************************************************************
    ** Function Call Name: ValPropType()
    ** Return Type: int
    ** Input: char
    ** Output: Validation T/F
    ** Purpose: To validate Property Type Loop
    *********************************************************************************/
    char ValPropType(char val_choice){
    	while (!( ((val_choice == 'R') || (val_choice == 'r')) || ((val_choice == 'C') || (val_choice == 'c')) || ((val_choice == 'M') || (val_choice == 'm')) ))
    	{
    		cout << "\nInvalid Property Type, Please Reenter: ";
    		cin >> val_choice;
    	}
    	return val_choice;
    }
    
    /*********************************************************************************
    ** Function Call Name: ValComm()
    ** Return Type: int
    ** Input: double
    ** Output: Validation T/F
    ** Purpose: To validate Commission Loop
    *********************************************************************************/
    double ValComm(double val_prop_sell){
    while (val_prop_sell <= NOTHING)
    					{
    						cout << "\nInvalid Data, Reenter Please:\t\t\t$ ";
    						cin >> val_prop_sell;
    					}
    	return val_prop_sell;
    }
    /*********************************************************************************
    ** Function Call Name: ValYesNo()
    ** Return Type: int
    ** Input: char
    ** Output: Validation T/F
    ** Purpose: To validate YesNo Loop
    *********************************************************************************/
    char ValYesNo(char val_yesno){
    while (!(( val_yesno == '1') || ( val_yesno == '0')))
    			{
    				cout << "Yes or NO!, Please Reenter: ";
    				cin  >> val_yesno;
    			}//endwhile
    	return val_yesno;
    }

  2. #2
    Registered User
    Join Date
    Jan 2005
    Location
    Estonia
    Posts
    131
    gdb gdb gdb

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  2. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  3. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  4. Building B-Tree from Arrays
    By 0rion in forum C Programming
    Replies: 1
    Last Post: 04-09-2005, 02:34 AM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM