diff options
author | Oskar <[email protected]> | 2024-08-01 12:11:23 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-08-01 12:11:23 +0200 |
commit | 0de72ab100011ab54f99f298e936327011ebc706 (patch) | |
tree | b0658b0e5d9b67b214e03177f7d08704038eed14 /2p41-1p22-v2.cpp | |
parent | a450487a18ec72ea3a3815bfaf17b2f701796b6f (diff) |
more exercises
Diffstat (limited to '2p41-1p22-v2.cpp')
-rw-r--r-- | 2p41-1p22-v2.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/2p41-1p22-v2.cpp b/2p41-1p22-v2.cpp new file mode 100644 index 0000000..25a49bd --- /dev/null +++ b/2p41-1p22-v2.cpp @@ -0,0 +1,46 @@ +#include <iostream> +#include "sales_item.hpp" + +/* + * + * 2.41 - 1.22 + * version 2, a bit more interactive but might not be desirable if using file redirections + * + */ + +struct SalesData { + std::string BookNo; + unsigned int UnitsSold = 0; + double Revenue = 0.0; +}; + +int main () { + + SalesData book1; + SalesData Sum; + if(std::cin >> Sum.BookNo >> Sum.UnitsSold >> Sum.Revenue) { + while(std::cin >> book1.BookNo >> book1.UnitsSold >> book1.Revenue) { + if(Sum.BookNo == book1.BookNo) { + Sum.UnitsSold += book1.UnitsSold; + Sum.Revenue += book1.Revenue; + } else { + std::cout << "These books do not have the same ISBN" << std::endl; + while(1) { + std::string yesno; + std::cout << "Do you wish to continue? Yes/No " << std::endl; + std::cin >> yesno; + if(yesno == "Yes") { + break; + } else if(yesno == "No") { + return 0; + } + } + continue; + } + } + } + + std::cout << Sum.BookNo << " " << Sum.UnitsSold << " " << Sum.Revenue << std::endl; + + return 0; +} |