From df3a5a68aae311e0797deaa7944ca6a37865da5b Mon Sep 17 00:00:00 2001 From: bartvbl <bartvblokl@gmail.com> Date: Mon, 17 Feb 2025 18:43:08 +0100 Subject: [PATCH] Added handout for lecture 9 --- .../Example - Scope/skop_eksempel.cpp | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 templates/_folder_Lectures/_folder_Lecture 09/Example - Scope/skop_eksempel.cpp diff --git a/templates/_folder_Lectures/_folder_Lecture 09/Example - Scope/skop_eksempel.cpp b/templates/_folder_Lectures/_folder_Lecture 09/Example - Scope/skop_eksempel.cpp new file mode 100644 index 0000000..f4296b5 --- /dev/null +++ b/templates/_folder_Lectures/_folder_Lecture 09/Example - Scope/skop_eksempel.cpp @@ -0,0 +1,36 @@ +#include <vector> +#include <iostream> + +//------------------------------------------------------------------------------' +// Eksempel fra gjesteforelesning 18.03.25 +// Skop + +double finnRabatt(double p) { + return 0.1 * p; +} + +int main() { + std::vector<double> priser {50, 10}; + double totalRabatt = 0; + + for (int i = 0; i < priser.size(); i++) { + double pris = priser.at(i); + + if (pris > 20) { + totalRabatt += finnRabatt(pris); + } + } + + std::string melding = "Rabatt på varen er: "; + + if (priser.size() > 1){ + std::string melding = "Rabatt på varene er: "; + std::cout << "Vi har flere varer." << std::endl; + std::cout << melding << std::endl; + } + + std::cout << melding << totalRabatt << std::endl; + return 0; +} + +//------------------------------------------------------------------------------ -- GitLab