From 6846701f11384fb12190109109acd60aa37b4e28 Mon Sep 17 00:00:00 2001 From: ganome Date: Sun, 25 Aug 2024 13:52:03 -0600 Subject: [PATCH] Finished day 2 exercise - added Subtract() --- .gitignore | 1 + cpp/ANSI/W1/Day2/Ex.5/Makefile | 13 +++++++++++++ cpp/ANSI/W1/Day2/Ex.5/main.cpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 cpp/ANSI/W1/Day2/Ex.5/Makefile create mode 100644 cpp/ANSI/W1/Day2/Ex.5/main.cpp diff --git a/.gitignore b/.gitignore index 1c232f6..31e7a7e 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ cpp/ANSI/W1/Day2/2.4/namespace-std cpp/ANSI/W1/Day2/2.5/comments cpp/ANSI/W1/Day2/2.6/functions cpp/ANSI/W1/Day2/2.7/function-math +cpp/ANSI/W1/Day2/Ex.5/function-math diff --git a/cpp/ANSI/W1/Day2/Ex.5/Makefile b/cpp/ANSI/W1/Day2/Ex.5/Makefile new file mode 100644 index 0000000..610e835 --- /dev/null +++ b/cpp/ANSI/W1/Day2/Ex.5/Makefile @@ -0,0 +1,13 @@ +CFLAGS = -std=c++03 -O2 +LDFLAGS = -lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi + +1.1: main.cpp + c++ $(CFLAGS) -o function-math main.cpp $(LDFLAGS) + +.PHONY: test clean + +test: function-math + ./function-math + +clean: + rm -f function-math diff --git a/cpp/ANSI/W1/Day2/Ex.5/main.cpp b/cpp/ANSI/W1/Day2/Ex.5/main.cpp new file mode 100644 index 0000000..4a1410c --- /dev/null +++ b/cpp/ANSI/W1/Day2/Ex.5/main.cpp @@ -0,0 +1,30 @@ +// Demonstrate some math using a function +#include +int Add( int first, int second) +{ + std::cout << "In Add() function, recived " << first << " and " << second << "\n"; + return(first + second); +} + +int Subtract( int first, int second) +{ + std::cout << "In the Subtract() Function, received " << first << " and " << second << "\n"; + return (first-second); +} + +int main() +{ + using namespace std; + + cout << "I'm in the main() function!\n"; + int a, b, c; // Declare some variables adding + cout << "Enter two numbers: "; + cin >> a; + cin >> b; + cout << "\nCalling Subtract() Function from main()\n"; + c=Subtract(a,b); + cout << "\nBack in Main()\n"; + cout << "c was set to:\t" << c; + cout << "\nExiting...\n\n"; + return 0; +} \ No newline at end of file