summaryrefslogtreecommitdiff
path: root/3.1-v3-2.cpp
blob: 9da81dba3a7cbe44eea3e83dcd8d8f85dcdad15e (plain)
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
#include <iostream>
#include "sales_data.hpp"

/*
 *
 * 2.41 - 1.22
 * version 2, a bit more interactive but might not be desirable if using file redirections
 *
 */
using std::cout;
using std::cin;
using std::endl;
int main () {
	
	SalesData book1;
	SalesData Sum;
	if(cin >> Sum.BookNo >> Sum.UnitsSold >> Sum.Revenue) {
		while(cin >> book1.BookNo >> book1.UnitsSold >> book1.Revenue) {
			if(Sum.BookNo == book1.BookNo) {
				Sum.UnitsSold += book1.UnitsSold;
				Sum.Revenue += book1.Revenue;
			} else {
				cout << "These books do not have the same ISBN" << endl;
				while(1) {
					std::string yesno;
					cout << "Do you wish to continue? Yes/No " << endl;
					cin >> yesno;
					if(yesno == "Yes") {
						break;
					} else if(yesno == "No") {
						return 0;
				    }
				}
				continue;
			}
		}
	}
	
	cout << Sum.BookNo << " " << Sum.UnitsSold << " " << Sum.Revenue << endl;
	
	return 0;
}