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