Finished day 2 exercise - added Subtract()

This commit is contained in:
ganome 2024-08-25 13:52:03 -06:00
parent 8ef4e679ce
commit 6846701f11
Signed by untrusted user who does not match committer: Ganome
GPG Key ID: 944DE53336D81B83
3 changed files with 44 additions and 0 deletions

1
.gitignore vendored
View File

@ -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

View File

@ -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

View File

@ -0,0 +1,30 @@
// Demonstrate some math using a function
#include <iostream>
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;
}