Finished day 2 exercise - added Subtract()
This commit is contained in:
parent
8ef4e679ce
commit
6846701f11
1
.gitignore
vendored
1
.gitignore
vendored
@ -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
|
||||
|
||||
13
cpp/ANSI/W1/Day2/Ex.5/Makefile
Normal file
13
cpp/ANSI/W1/Day2/Ex.5/Makefile
Normal 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
|
||||
30
cpp/ANSI/W1/Day2/Ex.5/main.cpp
Normal file
30
cpp/ANSI/W1/Day2/Ex.5/main.cpp
Normal 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;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user