This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[Fwd: [Fwd: documentation bug]]





I'm having a very consistent problem on a simple program working with
two-dimensional arrays.  I've attached my source code (it's only about 3
pages, neatly spaced, with 1 page of documentation), and near the end of
my program you can see my comments regarding the errors.  This error
occurs regardless of the original values within my array.

I emailed my professor my code and she could not duplicate my problem on
her Borland compiler.  She analyzed my code and said it should work.  I
am at a dead standstill on my school project until I can get this
resolved.  To test my code (a simple quarterly sales program for a
company with six divisions), I am entering in $10.00 as the total
quarterly sales per the six divisions for the first quarter, and then
answering 'N' to the question for whether second quarter sales have been
finalized.

Therefore, there should be zero sales for all quarters except the first,
and total company sales should equal $60.00, year-to-date.  These first
two arrays & calculations work fine.  However, when I display the array
to show me the total company sales per quarter, year-to-date, it should
show: Q1-$10.00, Q2-$0.00, Q3-$0.00, Q4-$0.00; but instead shows:
Q1-$62.15, Q2-$2.02, Q3-$2.04, Q4-$2.01.

This problem is consistent regardless of the values in the other arrays;
in the final array, it always adds $2.15 to Q1, $2.02 to Q2, $2.04 to
Q3, and $2.01 to Q4.  This problem happens regardless of whether I use
this code to build a project under Code Fusion, or whether I simply use
g++ to create an executable from the command line.

Please help!

Open Source Enthusiast,
Charles Mire



 
 
*sigh*  Marketing names.  Insight is installed as gdb.  If you run gdb
without any arguments you will get the Insight interface.
Thanks for the info here.  I was beginning to wonder if I was going crazy or something.  I did try invoking gdb (and maybe this is ignorance on my part), by typing gdb at the command line, but all I get is the command-line interface of gdb.  I looked over the instructions on page 192 of the manual for how to invoke Insight from Source-Navigator.  My settings match exactly what is in the manual; however, when I click on Debugger from the menu, I get a window that looks like the command-line interface of gdb, and it says "GDB Child--Do Not Terminate!", but nothing happens after that.  What else am I doing wrong?  Did I maybe not install something right?  I'm guessing my system is still running the gdb that came with my linux installation, and not the gdb that is actually Insight.
 
I'll let you try it with gdb first.  If you still can't figure out the
problem go ahead and send it directly to me.  Try to make it a little
smaller if you can.
I'm attaching the code.  When printed out, it's only about four pages, and I made all the tabs nice and neat so it should be easy to read.  I didn't remove any code because I wasn't sure how much to leave for you to understand the problem.  I thought maybe the build somehow corrupted the first target and object files, so I wiped out the entire project and copied the source code to a different directory; and then created a new project in a new working directory using the copied source code.  I got the same weird results, which are commented in at the last few lines of my program.  No matter what, this problem is very consistent (see my next note about g++).  I know you will probably laugh a little, because I'm such an amateur, so bear with me.

Also, I tried compiling my source from the command line, using g++, and then ran the resulting program--I got the same results....so maybe I need to look for a patch for g++ (if so, can you direct me to a good place to get such a patch)?  Or maybe my Pentium II-400 is goofing on the math...?

Thanks again for your prompt help.

Charles Mire
 
 

//Charles Mire
//This program will calculate a company's quarterly sales information
//based on user input.

/*
	Procedure
	-------------
	1.	Input
		a)	Sales Info for each Quarter per Division
	2.	Validation
		a)	No negative numbers for sales
		b)	No increase/decrease for First Quarter per Division
		c)	No increase/decrease for First Quarter for Company
	3.	Calculation
		a)	increase/decrease from previous quarter by Division
		b)	increase/decrease from previous quarter by Company
		c)	Total Quarterly Sales for Company
		d)	Average Quarterly Sales per Division
		e)	Average Quarterly Sales for Company
		f)	Division with the highest Quarterly Sales
	
	
	Functions
	-------------
		a)	qsales_fig	-	quarterly sales function
		b)	qinc_dec		-	increase/decrease function for Divisions
		c)	qtot_sales	-	quarterly total sales
		d)	co_qinc_dec	-	increase/decrease for company
		e)	avg_qsalesd	-	average quarterly sales for Divisions
		f)	avg_qsalesc	-	average quarterly sales for Company
		g)	div_high		-	Division with the highest sales per quarter
		
	Variable Dictionary
	---------------------
		sales_fig			-	array of quarterly sales figures by Division
		tot_qsales		-	total company sales for quarter
		tot_sales			-	total company sales to date
		inc_dec				-	array of quarterly inc/dec amount by Division
		co_inc_dec		-	array of quarterly inc/dec amount for Company
		count1				-	counter for the four quarters
		count2				-	counter for the six divisions
		answer				-	variable for user input
		
		
		
		
		
		
*/

#include <iostream.h>
#include <iomanip.h>
#include <math.h>
#include <stdlib.h>

//Function Prototypes
float qsales_fig (float[4][6], int&, int&);
float tot_co_sales (float&, float[4][6]);
float qtot_sales (float[4], float[4][6]);



//Function to clear screen
//int erase (void)
	

//Function to get quarterly sales input
float qsales_fig (float sales_fig [4][6], int &count1, int &count2)
{
	int count5;
	
	
		
		for (count2 = 0, count5 = 1; count2 < 6, count5 <=6; count2++, count5++)
		{
		
			do
			{
			cout << "Enter the sales figures for Quarter ";
			cout << count1+1 << " for Division ";
			cout << count5 << ":  $";
			cin >> sales_fig [count1][count2];
			cin.ignore();
			if (sales_fig [count1][count2] < 0.00)
				{
				cout << "\n\nYou must enter a number greater than 0!";
				cout << "\n\nPlease re-enter a positive sales figure!";
				}
			}while (sales_fig [count1][count2] < 0.00);
		}
		
	return sales_fig [count1][count2];
}


//Function to calculate total year-to-date sales for company
float tot_co_sales (float &tot_sales, float sales_fig [4][6])
{
	int count1, count2;
	
	for (count1 = 0; count1 < 4 ; count1++)
		{
		for (count2 = 0; count2 < 6; count2++)
			{
			tot_sales += sales_fig [count1][count2];
			}
		}
	return tot_sales;
}


//Function to calculate total quarterly sales for company
float qtot_sales (float tot_qsales [4], float sales_fig [4][6])
{
	int countA, countB;
	for (countA = 0; countA < 4; countA++)
	{
		for (countB = 0; countB < 6; countB++)
		{
		tot_qsales [countA] += sales_fig [countA][countB];
		}
	}
	return tot_qsales [countA];
}



int main (int)

{
	float sales_fig [4][6];
	float tot_sales;
	float tot_qsales [4];
	int count1 = 0;
	int count2 = 0;
	int flag = 0;
	int count3, count4;
	char answer, ch;
	
	cout << "Are the sales figures finalized for the First Quarter? ";
	cin >> answer;
	cin.ignore();
	if (answer == 'Y' || answer == 'y')
	{
		count1 = 0;
		flag = 0;
		qsales_fig (sales_fig, count1, count2);
	}
	if (answer == 'N' || answer == 'n')
	{
		cout << "Total Sales for all Divisions is $0.00";
		cout << "\n\n\nPress enter to continue.";
		cin.get (ch);
		flag = 1;
		//exit();
	}
	if (flag == 0)
		{
		cout << "Are the sales figures finalized for the Second Quarter? ";
		cin >> answer;
		cin.ignore();
		if (answer == 'Y' || answer == 'y')
			{
				count1 = 1;
				flag = 0;
				qsales_fig (sales_fig, count1, count2);
			}
		if (answer == 'N' || answer == 'n')
			{	
				count1 = 1;
				flag = 2;
				for (count4 = 0; count4 < 6; count4++)
					{
					sales_fig [1][count4] = 0.00;
					sales_fig [2][count4] = 0.00;
					sales_fig [3][count4] = 0.00;
					}
			}
		}
	if (flag == 0)
		{
		//continue;
		cout << "Are the sales figures finalized for the Third Quarter?";
		cin >> answer;
		cin.ignore();
		if (answer == 'Y' || answer == 'y')
			{
				count1 = 2;
				flag = 0;
				qsales_fig (sales_fig, count1, count2);
			}
		if (answer == 'N' || answer == 'n')
			{
				count1 = 2;
				flag = 3;
				for (count4 = 0; count4 < 6; count4++)
					{
						sales_fig [2][count4] = 0.00;
						sales_fig [3][count4] = 0.00;
					}
			}
		}			
	if (flag == 0)
		{
		//continue;
		cout << "Are the sales figures finalized for the Fourth Quarter?";
		cin >> answer;
		cin.ignore();
		if (answer == 'Y' || answer == 'y')
			{
				count1 = 3;
				qsales_fig (sales_fig, count1, count2);
			}
		if (answer == 'N' || answer == 'n')
			{
				count1 = 3;
				flag = 4;
				for (count4 = 0; count4 < 6; count4++)
				sales_fig [3][count4] = 0.00;
			}
		}						
	cout << endl << endl;
	if (flag != 1)
	{
		for (count3 = 0; count3 < 4; count3++)
		{
		cout.precision(2);
		cout.setf(ios::fixed | ios::showpoint);
		for (count4 = 0; count4 < 6; count4++)
			{
			cout << "\nQuarter " << count3+1 << " Division " << count4+1;
			cout << " : $" << sales_fig [count3][count4];
			}
		}
		tot_co_sales (tot_sales, sales_fig);
		cout << "\n\nTotal Year-To-Date Company Sales: $";
		cout << tot_sales;
		qtot_sales (tot_qsales, sales_fig);
		cout << "\n\nTotal Company Sales By Quarter";
		cout << "\n-----------------------------------";
		//Consistent numbers added as noted in comments on each line below
		cout << "\nQuarter 1:\t $" << tot_qsales[0];//+2.15
		cout << "\nQuarter 2:\t $" << tot_qsales[1];//+2.02
		cout << "\nQuarter 3:\t $" << tot_qsales[2];//+2.04
		cout << "\nQuarter 4:\t $" << tot_qsales[3];//+2.01
		
		
		
	}
}

					
					
					
		





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]