-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREC4.cpp
More file actions
91 lines (79 loc) · 2.75 KB
/
REC4.cpp
File metadata and controls
91 lines (79 loc) · 2.75 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
// include cmath, iostream and iomanip
#include <cmath>
#include <iostream>
#include <iomanip>
using namespace std;
// set up main function
int main(){
// identify variables
int userVelocity, finalVelocity;
char fuelType;
int x = 20;
// prompt user
cout << "Enter the initial velocity:" << endl;
cin >> userVelocity;
cout << "Enter the fuel type:" << endl;
cin >> fuelType;
// create if statements for errors
if (userVelocity < 0){
cout << "Please enter valid velocity." << endl;
}
if (fuelType != 'A' || fuelType != 'B' || fuelType != 'C'){
cout << "Please enter valid fuel type." << endl;
}
// first if statement is if entered velocity is less than 10
if (userVelocity < 10 && userVelocity >= 0){
// add case statement for each entered fuel type and use each acceleration based upon that
switch (fuelType){
case 'A':
finalVelocity = userVelocity + (5*x);
cout << "The final velocity is " << finalVelocity << " m/s." << endl;
break;
case 'B':
finalVelocity = userVelocity + (10*x);
cout << "The final velocity is " << finalVelocity << " m/s." << endl;
break;
case 'C':
finalVelocity = userVelocity + (20*x);
cout << "The final velocity is " << finalVelocity << " m/s." << endl;
break;
}
}
// second if statement is if entered velocity is between 10 and 40
if (userVelocity >= 10 && userVelocity <= 40){
// add case statement for each entered fuel type and use each acceleration based upon that
switch (fuelType){
case 'A':
finalVelocity = userVelocity + (6*x);
cout << "The final velocity is " << finalVelocity << " m/s." << endl;
break;
case 'B':
finalVelocity = userVelocity + (12*x);
cout << "The final velocity is " << finalVelocity << " m/s." << endl;
break;
case 'C':
finalVelocity = userVelocity + (24*x);
cout << "The final velocity is " << finalVelocity << " m/s." << endl;
break;
}
}
// third if statement is if entered velocity is greater than 40
if (userVelocity > 40){
// add case statement for each entered fuel type and use each acceleration based upon that
switch (fuelType){
case 'A':
finalVelocity = userVelocity + (3*x);
cout << "The final velocity is " << finalVelocity << " m/s." << endl;
break;
case 'B':
finalVelocity = userVelocity + (6*x);
cout << "The final velocity is " << finalVelocity << " m/s." << endl;
break;
case 'C':
finalVelocity = userVelocity + (9*x);
cout << "The final velocity is " << finalVelocity << " m/s." << endl;
break;
}
}
return 0;
}