-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstop.cpp
77 lines (65 loc) · 2.37 KB
/
stop.cpp
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include "timer.h"
#include "runner.h"
void selectOption(char& i);
void singleRunnerStopwatch(Timer& timer, Runner& runner);
int main (){
Timer timer;
Runner runner("John", 20, 92.2f);
singleRunnerStopwatch(timer, runner);
std::cout << "Your total time for all 3 laps: " << runner.addLapTimes();
std::cout << std::endl;
runner.printLaps();
std::cout << std::endl;
return 0;
}
void selectOption(char& i){
std::cout << "Select option:" << std::endl;
std::cout << "s. Start/Restart" << std::endl;
std::cout << "l. Lap" << std::endl;
std::cout << "e. End" << std::endl;
std::cout << "Option: ";
std::cin >> i;
}
void singleRunnerStopwatch(Timer& timer, Runner& runner){
char input = 'a';
int count = 0;
while (input != 'e' && count < 3){
selectOption(input);
switch (input){
case 's': //start/restart
count = 0;
std::cout << "Starting Stopwatch:" << std::endl;
timer.Restart();
//timer.PrintTimeStamp(); // don't really need to print this here
//runner.setLaps(count, 0.0f);
break;
case 'l': //lap
// accounting for 3 laps:
switch (count){
case 0: //fallthrough:
case 1:
std::cout << "Lapping Stopwatch:" << std::endl;
timer.PrintTimeStamp();
runner.setLapTime(timer.GetDeltaTime());
++count;
break;
case 2:
std::cout << "Final Time:" << std::endl;
timer.PrintTimeStamp();
runner.setLapTime(timer.GetDeltaTime());
runner.setBestTime(timer.GetDeltaTime());
++count;
input = 'e'; // end of input
std::cout << "Good Job! Don't forget to hydrate!" << std::endl;
break;
default:
std::cout << "ABORT: There was a problem with counting laps" << std::endl;
break;
}
break;
default:
std::cout << "Invalid Entry! Make another Selection." << std::endl;
}
}
}