code not showing correct output.

I need some assistance with this for some reason the output is not coming out correctly. I am missing the Department one label at the beginning and then at the end I am missing the total sales volume. I also notice that it shows the wrong department in the department 1 through 4 areas under total value and merchandise sold. Can anyone point me in the right direction as to what I did wrong here.

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
#include <iostream>
	 #include <fstream>
	 #include <cstdlib>
	 
	 int main()
	 {
		// define variables 
		int Dept = 0;
		char Item[25] = {" "};
		int holdDept = 0;	
		int Quantity = 0;
		double Price = 0.00;	
		double Total_price = 0.00;
        int	Total_quantity = 0;
        
        std::ifstream keithbyersIn;	
		std::cout.setf(std::ios::showpoint | std::ios::fixed);
		std::cout.precision(2);
		keithbyersIn.open("final.txt", std::ios::in);	
		if(!keithbyersIn)		
		{
			std::cerr << "\n\nInput file not opened properly" 
					<< std::endl << std::endl;
			exit(-1);
		}
	
		keithbyersIn >> Dept
			   >> Item
			   >> Quantity
               >> Price;	
		if(!keithbyersIn.eof())      
		{
			holdDept = Dept;
		    std::cout << "" << std::endl;
			std::cout << "Item Description      Total Sold" 
					<< std::endl;
			while(!keithbyersIn.eof())
            {
				if(holdDept != Dept)
				{
			std::cout << "\t\tDepartment " << Dept << " Total Sales Volume: "	
            << Total_price << std::endl;
            std::cout << "\t\tDepartment " << Dept << " Total Merchandise Sold: "	
            << Total_quantity << std::endl;
            std::cout << " " << std::endl;
            		Total_price = 0.0;
            		Total_quantity = 0;
					holdDept = Dept;
					std::cout << "   Department " 
							<< Dept << std::endl;
					std::cout << "Item Description      Total Sold" 
							<< std::endl;
				}
					std::cout << "   " << Item
							<< "\t\t" << Price 
							<< std::endl;
					Total_price += Price;
					Total_quantity += Quantity;
					keithbyersIn >> Dept
						   >> Item
						   >> Quantity
                           >> Price;
			}
			std::cout << "\t\tDepartment " << Dept << "Total Sales Volume: " 
					<< std::endl;
	        std::cout << "\t\tDepartment " << Dept << "Total Merchandise Sold: "	
            << Total_quantity << std::endl;
			Total_price += Price;
			Total_quantity += Quantity;
		}
		keithbyersIn.close();
		return(0);
	}


here's the output with everything marked in bold

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
Missing Department 1 here
Item Description      Total Sold
   Stereos              150.00
   Cameras              130.00
   Videos               30.00
                Department 2 Total Sales Volume: 310.00
                Department 2 Total Merchandise Sold: 145

   Department 2
Item Description      Total Sold
   Socks                4.00
   Shirts               6.00
   Pants                8.00
                Department 3 Total Sales Volume: 18.00
                Department 3 Total Merchandise Sold: 190

   Department 3
Item Description      Total Sold
   Perfume              50.00
   Makeup               75.00
   Eyeliner             15.00
                Department 4 Total Sales Volume: 140.00
                Department 4 Total Merchandise Sold: 125
   Department 4
Item Description      Total Sold
   Sockets              70.00
   CarWax               20.00
   Wipers               30.00
                Department 5 Total Sales Volume: 120.00
                Department 5 Total Merchandise Sold: 190

   Department 5
Item Description      Total Sold
   Plates               70.00
   Forks                30.00
   China                120.00
                Department 5Total Sales Volume:
                Department 5Total Merchandise Sold: 950
Last edited on
Topic archived. No new replies allowed.