Student Needing Help

I need to be able to add the sales up and average them out. Could i put the equation in main to calculate the total and average them out? This is just the start I am not finished.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 struct CorpData
{
	string divisionName;
	double totalSales;
	double firstQuarterSales;
	double secondQuarterSales;
	double thirdQuarterSales;
	double fourthQuarterSales;
	double averageQuarterlySales;

	CorpData(string dN, double tS, double fQS,double sQS, double tQS, double forQS, double aQS);  //Contructor.
}

//Define the constructor.
CorpData::CorpData(string dN, double tS, double fQS, double sQS, double tQS, double forQS, double aQS)
{
	divisionName = dN;
	totalSales = tS;
	firstQuarterSales = fQS;
	secondQuarterSales = sQS;
	thirdQuarterSales = tQS;
	fourthQuarterSales = forQS;
}

//Function.
void displayCorpInfo(CorpData corpName)
{
	cout << "Division Name: " << corpName.divisionName << endl;
	cout << "First Quarter Sales; $" << corpName.firstQuarterSales << endl;
	cout << "Second Quater Sales: $" << corpName.secondQuarterSales << endl;
	cout << "Third Quarter Sales: $" << corpName.thirdQuarterSales << endl;
	cout << "Fourth Quarter Sales: $" << corpName.fourthQuarterSales << endl;
	cout << "Average Quarterly Sales: $" << corpName.averageQuarterlySales <<endl;
	cout << "Total Annual Average: $" << corpName.totalSales << endl;
}

int main()
{
           //Equation here?    
	CorpData div1("North Division", 25000, 54543, 67890, 54987,need total and average)
Could i put the equation in main to calculate the total and average them out?

You could - but if the point of the exercise is to learn how to write functions, or even how to write methods of a class, then it would defeat the point.
i went ahead and did it without the equation. I have a different problem know. I have to combine two programs into one when i turn it in but, I get an error on my structure for my second program. its two seperate programs both have a structure in them. if need I can post how I have them together so you can see.
Have you defined the structure in a header file? Are you including that header in your second program?

if need I can post how I have them together so you can see.

Since very few members of this forum are mind-readers, I think you might have to.
Here are my two program together and this is the error I get: function 'int main(void)' already has a body so what do i do I have never come across this error before. Ihave to go to work and will not get of till 8 i will check back when I can.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
#include <string>

using namespace std;

struct MovieData
{
	string title;                                                                  //Title of movie.
	string director;                                                               //Director's name.
	unsigned int    yearReleased;                                                  // Year the movie was released.
	unsigned int    runningTime;		                                           //Running time in miuntes.
	double    productionCost;                                                      // Production Cost.
	double    yearRevenue;                                                        // First years revenue.
	MovieData(string title, string dir, unsigned int yr, unsigned int rT, double pC, double yR); //Constructor
};

//Define the constructor 
MovieData::MovieData(string title, string dir,  unsigned int yr,  unsigned int rT, double pC, double yR)
{
	title = title;
	director = dir;
	yearReleased = yr;
	runningTime = rT;
	productionCost = pC;
	yearRevenue = yR;
}

void displayMovieInfo(MovieData movieName)                              //function to display the movie info.
{
	cout << "---------------" << endl;
	cout << "Title: " << movieName.title << endl;
	cout << "Director: " << movieName.director << endl;
	cout << "Year Released: " << movieName.yearReleased << endl;
	cout << "Running Time: " << movieName.runningTime << "mins" << endl;
	cout << "Production Cost: $" << movieName.productionCost << " million" << endl;
	cout <<  "First year Revenues: $" << movieName.yearRevenue << " million" << endl;
	cout << "---------------\n" << endl;
}

int main()
{
	//Two MovieData variables using the constructor
	MovieData movie1("Twilight", "Catherine Hardwicke", 2008, 121,37, 392);
	MovieData movie2("The Watchmen- Director's Cut", "Zack Snyder", 20, 186, 120, 55.7);

	//Displaying  the movie info using the displayMovieInfo() function
	displayMovieInfo(movie1);
	displayMovieInfo(movie2);

	system("pause");
	system("cls");
}

   struct CorpData
{
	string divisionName;
	double firstQuarterSales;
	double secondQuarterSales;
	double thirdQuarterSales;
	double fourthQuarterSales;
	double totalSales;
	double averageQuarterlySales;
	CorpData(string dN, double fQS,double sQS, double tQS, double forQS, double aQS,double tS);  //Contructor.
};

//Define the constructor.
CorpData::CorpData(string dN, double fQS, double sQS, double tQS, double forQS, double aQS, double tS)
{
	divisionName = dN;
	firstQuarterSales = fQS;
	secondQuarterSales = sQS;
	thirdQuarterSales = tQS;
	fourthQuarterSales = forQS;
	averageQuarterlySales = aQS;
	totalSales = tS;
}

//Function.
void displayCorpInfo(CorpData corpName)
{
	cout << "-----------------------------------" << endl;
		cout  << endl;
	cout << "Division Name: " << corpName.divisionName << endl;
	cout << "First Quarter Sales; $" << corpName.firstQuarterSales << endl;
	cout << "Second Quater Sales: $" << corpName.secondQuarterSales << endl;
	cout << "Third Quarter Sales: $" << corpName.thirdQuarterSales << endl;
	cout << "Fourth Quarter Sales: $" << corpName.fourthQuarterSales << endl;
	cout << "Average Quarterly Sales: $" << corpName.averageQuarterlySales <<endl;
	cout << "Total Annual Average: $" << corpName.totalSales << endl;
	cout << endl;
	cout <<"------------------------------------" << endl;
}

int main()
{
	//CorpData variables using the constructor.
	CorpData div1("North Division", 25000, 54543, 67890, 54987, 50605, 202420);
	CorpData div2("South Division", 56098, 23456, 12345, 34543, 31610.50, 126442);
	CorpData div3("West Division", 34567, 54321, 98765, 78987, 66660, 266640);
	CorpData div4("East Division", 54678, 43123, 12345, 34567, 36178.25, 144713);

	//Display the Copr info using displayCorpInfo() function.
	displayCorpInfo(div1);
	displayCorpInfo(div2);
	displayCorpInfo(div3);
	displayCorpInfo(div4);

	system("pause");
	return 0;
}

Last edited on
OK, so that has nothing to do with a structure. The error message tells you everything you need to know - a program can only have one main function, and you've got two.

In fact, a program can't have more than one definition of any global function with the same name and signature. But, in particular, it makes no sense to have more that one main function, because how can a program have more than one entry point?
Last edited on
So then how do i combine them so i can turn them in?
Have a single main function that does all the things you need your single program to do.
Topic archived. No new replies allowed.