-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
65 lines (54 loc) · 1.91 KB
/
main.cpp
File metadata and controls
65 lines (54 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// Created by ABlack on 1/29/2020.
//
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <windows.h>
#include <cstdlib>
#include <cmath>
#include "Piano.h"
#include "GlobalFunctions.h"
#include <experimental/optional>
using std::experimental::optional;
using std::experimental::nullopt;
using std::experimental::make_optional;
using namespace std;
typedef optional<int> optInt;
int main() {
prompt();
unique_ptr<Piano> piano = make_unique<Piano>();
string input;
cout << "Input (Enter X to exit):";
bool valid = firstCheck(input);
bool keepGoing = true;
while(keepGoing) {
if (!valid) { // Invalid input. Continue until input is valid.
cout << "Invalid input. Please follow the format." << endl;
cout << "Input (Enter X to exit):";
valid = firstCheck(input);
} else if (valid && input != "X") { // Valid input that is not "X". Play the notes, then ask for input.
cout << "Enter note duration in milliseconds (enter 0 for default delay):";
int delay;
while (!(cin >> delay) || delay < 0) {
cout << "Invalid input. Enter note duration in milliseconds (enter 0 for default delay):";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
piano->setDelay(delay);
piano->play(input);
currentMusic(piano);
cout << "Go again? Input (Enter X to exit, or Y to play your music again):";
valid = firstCheck(input);
playAgain(piano, input, valid);
} else { // "X" was entered. Display message and end program.
cout << "\nThanks for Playing!" << endl;
keepGoing = false;
}
}
return 0;
}