Skip to content

Commit cc24bc8

Browse files
committed
Release 1.2.0 - Changed Calculation Method
1 parent 9b160e4 commit cc24bc8

File tree

3 files changed

+62
-114
lines changed

3 files changed

+62
-114
lines changed

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ include $(DEVKITPRO)/libnx/switch_rules
3131
# - <libnx folder>/default_icon.jpg
3232
#---------------------------------------------------------------------------------
3333
VERSION_MAJOR := 1
34-
VERSION_MINOR := 3
34+
VERSION_MINOR := 2
3535
VERSION_MICRO := 0
36-
STABLE := Developer GUI
36+
STABLE := Stable
3737

3838
APP_TITLE := Calculator_NX
3939
APP_AUTHOR := EmreTech
40-
APP_VERSION := ${STABLE} ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}
40+
APP_VERSION := ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO} ${STABLE}
4141

4242
#---------------------------------------------------------------------------------
4343
# CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder.
@@ -53,10 +53,10 @@ BUILD := build
5353
SOURCES := source
5454
DATA := data
5555
INCLUDES := include
56-
ROMFS := borealis/resources
57-
BOREALIS_PATH := borealis
56+
#ROMFS := borealis/resources
57+
#BOREALIS_PATH := borealis
5858

59-
OUT_SHADERS := shaders
59+
#OUT_SHADERS := shaders
6060

6161
#---------------------------------------------------------------------------------
6262
# options for code generation
@@ -81,7 +81,7 @@ LIBS := -lnx
8181
#---------------------------------------------------------------------------------
8282
LIBDIRS := $(PORTLIBS) $(LIBNX)
8383

84-
include $(TOPDIR)/borealis/library/borealis.mk
84+
#include $(TOPDIR)/borealis/library/borealis.mk
8585

8686
#---------------------------------------------------------------------------------
8787
# no real need to edit anything past this point unless you need to add additional

source/calculator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ namespace Calculator {
161161
float solve(std::vector<float>& vec, std::string_view operation) {
162162
float result = vec[0];
163163

164-
for (int i = 1; i < vec.size(); i++) {
164+
for (std::vector<float>::size_type i{ 1 }; i < vec.size(); i++) {
165165
auto current_num = vec[i];
166166

167167
switch (turnStringToIntOperator(operation)) {

source/main.cpp

Lines changed: 54 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,15 @@
11
// Include libraries for the calculator program
2-
#include <iostream>
3-
#include <string>
4-
#include <stdexcept>
5-
#include <exception>
6-
#include <vector>
7-
#include <utility>
8-
#include "calculator.hpp"
2+
#include <iostream> // For output to the user
3+
#include <sstream> // For converting whitespace into elements for a std::vector
4+
#include <string> // For std::string (used a lot in this program)
5+
#include <vector> // For std::vector (storing numbers yet to be calculated)
6+
#include <utility>
7+
#include "calculator.hpp" // For the actual Calculating meat
98

109
// Include additional libraries for the Switch program
11-
#include <cstdio>
12-
#include <cstdlib>
13-
#include <switch.h>
14-
15-
char* SoftwareKeyboard(Result rc, const char * guideText) {
16-
SwkbdConfig kbd;
17-
char * tmpoutstr;
18-
19-
rc = swkbdCreate(&kbd, 0);
20-
//printf("swkbdCreate(): 0x%x\n", rc);
21-
if (R_SUCCEEDED(rc)) {
22-
// Select a Preset to use, if any.
23-
swkbdConfigMakePresetDefault(&kbd);
24-
25-
// Optional, set any text if you want (see swkbd.h).
26-
//swkbdConfigSetOkButtonText(&kbd, "Submit");
27-
//swkbdConfigSetLeftOptionalSymbolKey(&kbd, "a");
28-
//swkbdConfigSetRightOptionalSymbolKey(&kbd, "b");
29-
//swkbdConfigSetHeaderText(&kbd, "Header");
30-
//swkbdConfigSetSubText(&kbd, "Sub");
31-
swkbdConfigSetGuideText(&kbd, guideText);
32-
33-
//Optional, can be removed if not using TextCheck.
34-
35-
// Set the initial string if you want.
36-
//swkbdConfigSetInitialText(&kbd, "Initial");
37-
38-
// You can also use swkbdConfigSet*() funcs if you want.
39-
40-
//printf("Running swkbdShow...\n");
41-
rc = swkbdShow(&kbd, tmpoutstr, sizeof(tmpoutstr));
42-
//printf("swkbdShow(): 0x%x\n", rc);
43-
44-
/*if (R_SUCCEEDED(rc)) {
45-
printf("out str: %s\n", tmpoutstr);
46-
}*/
47-
swkbdClose(&kbd);
48-
}
49-
50-
return tmpoutstr;
51-
}
52-
53-
void calculateVectorInts(std::string operation, MathCalculator& calculator, Result& rc) {
54-
std::string number;
55-
char * tmpoutstr;
56-
bool inputComplete = false;
57-
58-
while(!inputComplete) {
59-
tmpoutstr = SoftwareKeyboard(rc, "Enter one number at a time (q to stop)");
60-
number = std::string(tmpoutstr);
61-
62-
if (number == "q") {
63-
inputComplete = true;
64-
} else {
65-
if (calculator.contains_number(number)) {
66-
calculator.setVector(std::stoi(number));
67-
} else inputComplete = true;
68-
}
69-
70-
int answer = calculator.CalculateMoreInt(operation);
71-
std::cout << "The answer is: " << answer << "\n";
72-
}
73-
}
74-
75-
void calculateTwoInts(std::string operation, MathCalculator& calculator, Result& rc) {
76-
std::string number1;
77-
std::string number2;
78-
79-
char * tmpoutstr = SoftwareKeyboard(rc, "Enter two numbers with a space in-between");
80-
std::string keyboardInput(tmpoutstr);
81-
82-
int pos = keyboardInput.find(" ");
83-
84-
number1 = keyboardInput.substr(0, pos);
85-
number2 = keyboardInput.substr(pos + 1);
86-
87-
int num1;
88-
int num2;
89-
90-
if (calculator.contains_number(number1) && calculator.contains_number(number2)) {
91-
num1 = std::stoi(number1);
92-
num2 = std::stoi(number2);
93-
94-
int answer = calculator.CalculateInt(operation, num1, num2);
95-
96-
std::cout << "The answer to " << num1 << " " << operation << " " << num2 << "is " << answer << "\n";
97-
} else return;
98-
}
10+
#include <cstdio> // C library (might be unused)
11+
#include <cstdlib> // C library (might be unused)
12+
#include <switch.h> // The important header for working the Switch
9913

10014
int main(int argc, char* argv[]) {
10115
consoleInit(NULL);
@@ -109,13 +23,12 @@ int main(int argc, char* argv[]) {
10923

11024
Result rc = 0;
11125

112-
std::vector<int> StoredInts{};
26+
std::vector<float> vec;
27+
std::string operation;
28+
char tmpoutstr[16] = {0};
11329

114-
MathCalculator calculator{StoredInts};
115-
std::string operation{};
116-
117-
std::cout << "Press up for Addition, \ndown for Subtraction, \nleft for Mutiplication, \nand right for Division." << "\n";
118-
std::cout << "L to Calculate, Plus to exit" << "\n";
30+
std::cout << "Press up for Addition, \ndown for Subtraction, \nleft for Mutiplication, \nand right for Division." << std::endl;
31+
std::cout << "L to Calculate, Plus to exit" << std::endl;
11932

12033
// Main loop
12134
while (appletMainLoop())
@@ -149,17 +62,52 @@ int main(int argc, char* argv[]) {
14962
}
15063

15164
if (kDown & HidNpadButton_L && !operation.empty()) {
152-
std::cout << "A for calculating more than 2 numbers, B for calculating only 2 numbers\n";
153-
if (kDown & HidNpadButton_A) {
154-
calculateVectorInts(operation, calculator, rc);
155-
} else if (kDown & HidNpadButton_B) {
156-
calculateTwoInts(operation, calculator, rc);
65+
std::string fullNums;
66+
67+
SwkbdConfig kbd;
68+
rc = swkbdCreate(&kbd, 0);
69+
70+
if (R_SUCCEEDED(rc)) {
71+
// Select a Preset to use, if any.
72+
swkbdConfigMakePresetDefault(&kbd);
73+
//swkbdConfigMakePresetPassword(&kbd);
74+
//swkbdConfigMakePresetUserName(&kbd);
75+
//swkbdConfigMakePresetDownloadCode(&kbd);
76+
77+
// Optional, set any text if you want (see swkbd.h).
78+
//swkbdConfigSetOkButtonText(&kbd, "Submit");
79+
//swkbdConfigSetLeftOptionalSymbolKey(&kbd, "a");
80+
//swkbdConfigSetRightOptionalSymbolKey(&kbd, "b");
81+
//swkbdConfigSetHeaderText(&kbd, "Header");
82+
//swkbdConfigSetSubText(&kbd, "Sub");
83+
swkbdConfigSetGuideText(&kbd, "Enter all numbers with a space in-between: ");
84+
85+
// Set the initial string if you want.
86+
//swkbdConfigSetInitialText(&kbd, "Initial");
87+
88+
// You can also use swkbdConfigSet*() funcs if you want.
89+
90+
//printf("Running swkbdShow...\n");
91+
rc = swkbdShow(&kbd, tmpoutstr, sizeof(tmpoutstr));
92+
//printf("swkbdShow(): 0x%x\n", rc);
93+
94+
swkbdClose(&kbd);
15795
}
15896

97+
std::istringstream iss(tmpoutstr);
98+
std::string Num;
99+
100+
while (iss >> Num) {
101+
vec.emplace_back(std::stof(Num));
102+
}
103+
104+
std::cout << "The answer is: " << Calculator::solve(vec, operation) << std::endl;
105+
159106
// I just noticed that the string below says \nand at some point
160107
std::cout << "Press up for Addition, \ndown for Subtraction, \nleft for Mutiplication, \nand right for Division." << "\n";
161108
std::cout << "L to Calculate, Plus to exit" << "\n";
162109

110+
vec.clear();
163111
}
164112

165113
//std::cout << operation << "\n";

0 commit comments

Comments
 (0)