-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp2_main.cpp
84 lines (64 loc) · 2.04 KB
/
p2_main.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
78
79
80
81
82
83
84
//
// main.cpp
// P2
//
// Created by Maria Palafox on 4/16/18.
// Copyright © 2018 Maria Palafox. All rights reserved.
//
#include <iostream>
#include <string>
using namespace std;
int main()
{
// added modifier to variable named constant numbers
const double FIRST_CHUNK = 155;
const double SECOND_CHUNKPM = 271;
const double SECOND_CHUNK = 255;
cout<< "Importer: ";
string importerName;
getline(cin,importerName);
//error 1
if (importerName == "")
{
cout<< "---"<<endl;
cout<< "You must enter an importer."<<endl;
return 0;
}
cout<< "Product value (in trillions): ";
double productValue;
cin >> productValue;
cin.ignore(10000, '\n');
cout.setf(ios::fixed);
cout.precision(2);
//error 2
if (productValue < 0)
{
cout<< "---" << endl;
cout << "The product value must not be negative." <<endl;
return 0;
}
cout << "Product: ";
string productName;
getline(cin,productName);
//error 3
if (productName == "")
{
cout<< "---" << endl;
cout<< "You must enter a product."<<endl;
return 0;
}
//i avoided using the OR and != in the else-if statements to prevent the condition from always being true. also I added in some constants to prevent messing up re typing the numbers.
double duty;
if (productValue <= 500)
duty = productValue * 0.31;
else if (productValue <= 900 && (productName == "pigs" || productName == "mud"))
duty = 0.29*(productValue - 500) + FIRST_CHUNK;
else if (productValue <= 900)
duty = 0.25*(productValue - 500) + FIRST_CHUNK;
else if (productValue > 900 && (productName == "pigs" || productName == "mud"))
duty = 0.22*(productValue - 900) + SECOND_CHUNKPM;
else
duty = 0.22*(productValue - 900) + SECOND_CHUNK;
cout<< "---" << endl;
cout<< "The import duty for " << importerName << " is G" << duty<< " trillion."<< endl;
}