Day 2, Part 1 complete; Part 2 start

This commit is contained in:
Blizzard Finnegan 2021-12-06 11:03:29 -05:00
parent ea4c7bb3f1
commit 22deef5120
4 changed files with 1068 additions and 0 deletions

1000
day2/data/input.txt Normal file

File diff suppressed because it is too large Load diff

BIN
day2/day2Part1 Executable file

Binary file not shown.

34
day2/day2Part1.cpp Normal file
View file

@ -0,0 +1,34 @@
#include <iostream>
#include <fstream>
using namespace std;
int main (void)
{
char direction[10];
int count = 0;
int totalForward = 0;
int totalVertical = 0;
int finalAnswer = 0;
ifstream readFile ("data/input.txt", ios::in);
while(readFile >> direction >> count)
{
switch (direction[0])
{
case 'f':
totalForward += count;
break;
case 'u':
totalVertical -= count;
break;
case 'd':
totalVertical += count;
break;
default:
cout << "Error!!!";
}
}
finalAnswer = totalVertical * totalForward;
cout << finalAnswer;
return 0;
}

34
day2/day2Part2.cpp Normal file
View file

@ -0,0 +1,34 @@
#include <iostream>
#include <fstream>
using namespace std;
int main (void)
{
char direction[10];
int count = 0;
int totalForward = 0;
int totalVertical = 0;
int finalAnswer = 0;
ifstream readFile ("data/input.txt", ios::in);
while(readFile >> direction >> count)
{
switch (direction[0])
{
case 'f':
totalForward += count;
break;
case 'u':
totalVertical -= count;
break;
case 'd':
totalVertical += count;
break;
default:
cout << "Error!!!";
}
}
finalAnswer = totalVertical * totalForward;
cout << finalAnswer;
return 0;
}