-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmini_project_v2.cpp
More file actions
107 lines (85 loc) · 2.93 KB
/
Copy pathmini_project_v2.cpp
File metadata and controls
107 lines (85 loc) · 2.93 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <vector>
#include <iostream>
using namespace std;
// this code is to practice strings and vectors
// hypotetical: you are going to adjust the speed
// of the serve machine by typing plus or minus
// to a coresponding motor. If the phrases
// "one" "two" "three" or "four" are typed the speed
// will clear back to zero and out put the
// machine has stopped then it will go to the
// speed assigned by the presets
// picks which motor to modify
int pick()
{
std::cout << "what motor do you want to adjust (1,2,3)" << std::endl;
int motor = 0;
std::cin >> motor;
return motor;
}
//this will add however much speed
// to whichever motor specified
int num()
{
std::cout << "How much do you want to add/subtract (1-10) "<< std::endl;
int num = 0;
std::cin >> num;
return num;
}
int main()
{
vector<int> v = {0, 0, 0};
std::cout << "you turned your motor on" << std::endl;
while (true)
{
std::cout << "motor one speed: " << v[0] << std::endl;
std::cout << "motor two speed: " << v[1] << std::endl;
std::cout << "motor three speed: " << v[2] << std::endl;
std::cout << "what would you like to do?" << std::endl;
std::cout << "(add, sub, end)" << std::endl;
std::string option;
std::cin >> option;
if (option == "add")
{
int motor = pick();
int amount = num();
if (amount + v[ motor -1 ] > 10)
{
std::cout<< "max speed"<< std::endl;
v.insert(v.begin() + motor - 1, 10);
v.erase(v.begin() + motor);
}
else if (amount + v[ motor - 1] <= 10)
{
v.insert(v.begin() + motor - 1, amount + v[motor - 1]);
v.erase(v.begin() + motor);
}
}
else if (option == "sub")
{
int motor = pick();
int amount = num();
if (v[ motor -1 ] - amount < 0)
{
std::cout<< "min speed"<< std::endl;
v.insert(v.begin() + motor - 1, 0);
v.erase(v.begin() + motor );
}
else if (v[ motor - 1] - amount >= 0)
{
v.insert(v.begin() + motor - 1, v[motor - 1] - amount);
v.erase(v.begin() + motor);
}
}
else if (option == "end")
{
break;
}
else
{
std::cout << "Invalid option" << std::endl;
}
}
std::cout << "you turned the machine off" << std::endl;
return 0;
}