From b21c717fdd26a58b935ac37c402528366f04c52a Mon Sep 17 00:00:00 2001 From: ZennDev1337 Date: Mon, 22 Jan 2024 10:26:02 +0100 Subject: [PATCH] 2.x Quiz --- dot vscode/tasks.json | 4 ++-- io.cpp | 14 ++++++++++++++ io.h | 4 ++++ main.cpp | 14 ++++---------- 4 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 io.cpp create mode 100644 io.h diff --git a/dot vscode/tasks.json b/dot vscode/tasks.json index ef2b39c..6037983 100644 --- a/dot vscode/tasks.json +++ b/dot vscode/tasks.json @@ -9,7 +9,7 @@ "-ggdb", "-std=c++20", "-pedantic-errors", - "${file}", + "${fileDirname}/**.cpp", "-o", "${fileDirname}\\build\\${fileBasenameNoExtension}.exe" ], @@ -30,7 +30,7 @@ "-DNDEBUG", "-std=c++20", "-pedantic-errors", - "${file}", + "${fileDirname}/**.cpp", "-o", "${fileDirname}\\build\\${fileBasenameNoExtension}.exe" ], diff --git a/io.cpp b/io.cpp new file mode 100644 index 0000000..6c03ca8 --- /dev/null +++ b/io.cpp @@ -0,0 +1,14 @@ +#include "io.h" +#include + +int readNumber() +{ + std::cout << "Enter a number to add: "; + int x{}; + std::cin >> x; + return x; +} +void writeAnswer(int x) +{ + std::cout << "The answer is: " << x << "\n"; +} \ No newline at end of file diff --git a/io.h b/io.h new file mode 100644 index 0000000..7c489bc --- /dev/null +++ b/io.h @@ -0,0 +1,4 @@ +#pragma once + +int readNumber(); +void writeAnswer(int x); \ No newline at end of file diff --git a/main.cpp b/main.cpp index bb43550..37ae2d9 100644 --- a/main.cpp +++ b/main.cpp @@ -1,17 +1,11 @@ #include // for std::cout - -// Definition of user-defined function doPrint() -void doPrint() // doPrint() is the called function in this example -{ - std::cout << "In doPrint()\n"; -} +#include "io.h" // Definition of function main() int main() { - std::cout << "Starting main()\n"; - doPrint(); // Interrupt main() by making a function call to doPrint(). main() is the caller. - std::cout << "Ending main()\n"; // this statement is executed after doPrint() ends - + int a{readNumber()}; + int b{readNumber()}; + writeAnswer(a + b); return 0; } \ No newline at end of file