From 0863591e1aa4a172e376dcdc9c3e0d2c39a63019 Mon Sep 17 00:00:00 2001 From: Oskar Date: Mon, 12 Aug 2024 17:13:23 +0200 Subject: more --- 3p36.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 3p36.cpp (limited to '3p36.cpp') diff --git a/3p36.cpp b/3p36.cpp new file mode 100644 index 0000000..3928de5 --- /dev/null +++ b/3p36.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +#include "sales_data.hpp" +#include "sales_item.hpp" + +/* + * + * 3.36 + * + * I found a little bit of strangeness when comparing the vectors with '==' + * If i input for example 5 1's to the first vector + * and then i enter maybe 2 1's to the 2nd vector + * and then afterwards hit CTRL+D, the vector evaluates + * as equal... Not sure if it's supposed to be like this, they clearly aren't the same... + */ + +int main () { + + constexpr size_t ArrSize = 5; + int arr1[ArrSize]; + int arr2[ArrSize]; + std::cout << "Input " << ArrSize << " numbers: " << std::endl; + for(auto &a : arr1) { + if(std::cin >> a) {} else { return -1; } + } + + std::cout << "Input " << ArrSize << " numbers: " << std::endl; + for(auto &a : arr2) { + if(std::cin >> a) {} else { return -1; } + } + + bool f = true; + for(size_t ii = 0 ; ii != ArrSize ; ++ii) { + if(arr1[ii] != arr2[ii]) { + std::cout << "The arrays are not equal." << std::endl; + f = false; + break; + } + } + + if(f == true) { + std::cout << "The arrays are equal." << std::endl; + } + + int a = 0; + std::vector vec1; + std::vector vec2; + std::cout << "Input " << ArrSize << " numbers: " << std::endl; + for(decltype(vec1.size()) i = 0 ; i != ArrSize ; ++i) { + if(std::cin >> a) {} else { break; } + vec1.push_back(a); + } + + std::cout << "Input " << ArrSize << " numbers: " << std::endl; + for(decltype(vec2.size()) i = 0 ; i != ArrSize ; ++i) { + if(std::cin >> a) {} else { break; } + vec2.push_back(a); + } + + if(vec1 != vec2) { + std::cout << "The vectors are not equal." << std::endl; + return 0; + } else if (vec1 == vec2) { + std::cout << "The vectors are equal." << std::endl; + } + + return 0; +} -- cgit v1.2.3