1
0

Multifile and header guard practise.

This commit is contained in:
Captain ALM 2022-08-14 15:47:03 +01:00
parent 1c0990b4d1
commit 3a4c93189d
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1
3 changed files with 29 additions and 18 deletions

View File

@ -1,25 +1,9 @@
#include <iostream> #include <iostream>
#include "utils.hpp"
int promptNumber(const char*);
void addSubTwoNumbers();
int main() int main()
{ {
std::cout << "Add and Subtract 2 Numbers:\n\n"; std::cout << "Add and Subtract 2 Numbers:\n\n";
addSubTwoNumbers(); utils::addSubTwoNumbers();
return 0; return 0;
} }
int promptNumber(const char* prompt) {
int toReturn {};
std::cout << prompt;
std::cin >> toReturn;
return toReturn;
}
void addSubTwoNumbers() {
int num1 {promptNumber("Enter a integer: ")};
int num2 {promptNumber("Enter another integer: ")};
std::cout << num1 << " + " << num2 << " = " << num1 + num2 << "\n";
std::cout << num1 << " - " << num2 << " = " << num1 - num2 << "\n";
}

19
utils.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <iostream>
namespace utils
{
int promptNumber(const char* prompt)
{
int toReturn {};
std::cout << prompt;
std::cin >> toReturn;
return toReturn;
}
void addSubTwoNumbers()
{
int num1 {promptNumber("Enter a integer: ")};
int num2 {promptNumber("Enter another integer: ")};
std::cout << num1 << " + " << num2 << " = " << num1 + num2 << "\n";
std::cout << num1 << " - " << num2 << " = " << num1 - num2 << "\n";
}
}

8
utils.hpp Normal file
View File

@ -0,0 +1,8 @@
#ifndef utils_H_
#define utils_H_
namespace utils
{
int promptNumber(const char*);
void addSubTwoNumbers();
}
#endif // utils_H_