hy can anyone help me out with this code plz

#include <iostream> //Declarations
#include <iomanip>
#include <fstream>
#include <cstdlib>

using namespace std;

double SaleSlcdDep();
double SaleALLDep();
double AveSaleALLDep();
double HighestSaleALLDep();
double alphatest1();
double alphatest2();
double menu();
int main()
{
	double sales[12];	//  Sales Input for the 12 departments
	double result;
	int ii;
	ofstream outfile ("system.dat");
	for(ii=0;ii<12;ii++)
	{
		cout << "Enter Sales For Department "  << ii+1 << '\n';
		cin >> sales[ii];
		alphatest2();
		while (!(sales<=0||sales>=0))
		{
			cout << "Error,Please ReEnter";
			cin >> sales[ii];
		}
		outfile << sales[ii] << '\n';

	}
	outfile.close();
	system ("cls");
	result=menu();
	

	return 0;
}

double menu()	//Input's Systems menu
{
	int result;
	double valA;double valB;
	double valC;double valD;
    cout << "+=============+\n";
    cout << "| System Menu |\n";
    cout << "+=============+\n\n";
    cout << "+=========================================================+\n";
    cout << "|                                                         |\n";
	cout << "|   1. Display sales for a specified Department.          |\n";
	cout << "|   2. Display sales for all Departments.                 |\n";
	cout << "|   3. Display average sales for all the Departments.     |\n";
	cout << "|   4. Display highest sales for all Departments.         |\n";
	cout << "|   5. Exit.                                              |\n";
	cout << "|                                                         |\n";
	cout << "+=========================================================+\n";
	cin >> result;
	system ("cls");
	
	switch (result)
	{	case 1:
        
		{valA=SaleSlcdDep();
			return 0;}
		case 2:
		{valB=SaleALLDep();
			return 0;}
		case 3:
		{valC=AveSaleALLDep();
			return 0;}
		case 4:
		{valD=HighestSaleALLDep();
			return 0;}
		case 5:
			return 0;
	}
	return 0;
}

double SaleSlcdDep()	//Sales Input for the Specific Departments
{
	int deptNo;
	int selection;
	int i;
	double sales[12];
	double valA;
	cout << "Please enter the Department Number :" << '\n';
	
	cout << "Department #1." << '\n';cout << "Department #2." << '\n';	
	cout << "Department #3." << '\n';cout << "Department #4." << '\n';	
	cout << "Department #5." << '\n';cout << "Department #6." << '\n';
	cout << "Department #7." << '\n';cout << "Department #8." << '\n';
	cout << "Department #9." << '\n';cout << "Department #10." << '\n';
	cout << "Department #11." << '\n';cout << "Department #12." << '\n';
	
	cin >> deptNo;
	alphatest1();
	deptNo=deptNo--;
	ifstream infile ("system.dat");
	for(i=0;i<11;i++)
		infile >> sales[i];
	cout << "Sales for Department " << deptNo++<< " = " << "$" << sales[deptNo] << '\n';
	infile.close();
	cout << "\n1. +----------------------+";
	cout << "\n   |Return to system menu |";
	cout << "\n   +----------------------+";
	cout << "\n5. Exit\n";
	cin >> selection;
	system ("cls");
	switch (selection)
	{
		case 1:
			valA=menu();
		case 2:
			return 0;
	}
return 0;
}

double  SaleALLDep()	//Veiw all of the Sales
{
	int selection;
	int i;
	double sales[12];
	double valA;
	system ("cls");
	ifstream infile ("system.dat");
	cout << "Department sales: " << '\n';
	for(i=0;i<12;i++)
	{
		infile >> sales[i];
		cout << i+1 << "=" << "$" << sales[i] << '\n';
	}
	infile.close();
	cout << "\n1.+---------------------+"; 
    cout << "\n  |Return to system menu|";
    cout << "\n  +---------------------+";
	cout << "\n5. Exit\n";
	cin >> selection;
	system ("cls");
	switch (selection)
	{
		case 1:
			valA=menu();
		case 2:
			return 0;
	}
	return 0;
}

double AveSaleALLDep()	//Average of all the sales
{
	int selection;
	int	i;
	double valA;
	double	sum;
	double	sales[12];
	sum = 0;
	system ("cls");
	ifstream infile ("system.dat");
	for(i=0;i<12;i++)
	{		
		infile >> sales[i];
		sum+=sales[i];
	}
	cout << "Average sales for all Departments = " << sum/12;
	infile.close();
    cout << "\n1.+---------------------+"; 
    cout << "\n  |Return to system menu|";
    cout << "\n  +---------------------+";
	cout << "\n5. Exit\n";
	system ("cls");
	switch (selection)
	{
		case 1:
			valA=menu();
		case 2:
			return 0;
	}
	return 0;
}

double HighestSaleALLDep()	//Highest sale recorded
{
	int selection;
	int	i;
	int	highdept;
	double sales[12];
	double valA;
	double high=0;
	system ("cls");
	ifstream infile ("system.dat");
	for(i=0;i<12;i++)
	{	
		infile >> sales[i];
		if(sales[i]>high)
		{
			high=sales[i];
			highdept=i;
		}
	}
	cout << "Highest sales = " << high << " for department " << highdept+1;
	infile.close();
    cout << "\n1.+---------------------+"; 
    cout << "\n  |Return to system menu|";
    cout << "\n  +---------------------+";
	cout << "\n5. Exit\n";
	cin >> selection;
	system ("cls");
	switch (selection)
	{
		case 1:
			valA=menu();
		case 2:
			return 0;
	}
	return 0;
}

double alphatest1()		//Valadidity test for function one input
{
	int selection;
	double valA;
	system ("cls");
	ifstream infile ("system.dat");
	while(!cin.good())
	{
		cout << "Error in Input";
		cin.clear();
		cin.ignore(20,'\n');
		cout << "\n1. Return to previous file";
		cout << "\n2. Return to system menu";
		cout << "\n3. Exit\n";
		cin >> selection;
		system ("cls");
		switch (selection)
		{
			case 1:
				valA=SaleSlcdDep();
			case 2:
				valA=menu();
			case 3:
				return 0;
		}
	system ("cls");
	menu();
	}
	return 0;
}

	double alphatest2()		//Valadidity test for initial sales input
{
	int selection;
	system ("cls");
	ifstream infile ("system.dat");
	while(!cin.good())
	{
		cout << "Error in Input";
		system ("cls");
		return 0;
	}
	return 0;
}

its soo bugged i donno how it even works lol
if anyone could help me out "//Average of all the sales" is not working fine and any other ones u notice
much appreciation
thanks

Recommended Answers

All 9 Replies

>i donno how it even works lol
Did you even write the code?

commented: Hit the nail on the head. +11
commented: s/my dog ate my homework/my dog wrote my homework/ +29

Post your compile errors,
and I'll have a look at it.

monkey_king it compiles but got few errors with it when i run it then enter 12 numbers then select option 3 it closes staright away, there is few more errors , if u jst copy the code run it , u will see.
I was also wondering if there is a way to change it make it look neater , shorter.

>i donno how it even works lol
Did you even write the code?

Ditto William Hemsworth. Did you write this? What exactly do you want us to do with this? Simply fix it and post the corrected version so you can turn it in?

Why would u think I dint write it, I just need others opinion to make it better, crash proof , because I’m still a beginner at this.

monkey_king it compiles but got few errors with it when i run it then enter 12 numbers then select option 3 it closes staright away, there is few more errors , if u jst copy the code run it , u will see.
I was also wondering if there is a way to change it make it look neater , shorter.

I have no intent of doing a copy paste of some code,
that you simply have copy pasted.

Selecting option tells the program to exit,
so exiting is really no error is it?

What are the other errors?

What do you want?
Do you want us to explain you the code line by line?

ok explain it line by line plz
and can u tell me how can i edit my first post

commented: Are you kidding? Explain it to someone who is too lazy to even type properly? -4

Why would u think I dint write it

Because you say that you have no idea how it works. If you have written it, you should be able to at least explain how you think it works and what you are trying to do.

ok explain it line by line plz
and can u tell me how can i edit my first post

I doubt anyone is going to be willing to go through it line by line and explain how it works. Explain what you are trying to do, pick a few lines, say what the problems are, and someone may explain what those lines do, assuming that you actually wrote it.

You can't edit a post after a certain length of time (can't remember the length of time).

can't remember the length of time

I believe it is 15 minutes.

btw:
>Spanki : line 25 or so of your code
while (!(sales<=0||sales>=0))------> very fancy way to say while false

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.