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
|
// Name: msglm
// Introduction: Summer Job Wage Calculator
// Description: a program that calculates a weekly wage, based on an hourly payrate and how many hours were worked; then calculates amounts for various categories of spending, along with how much of the weekly pay is leftover.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
const double tax = 0.15;
int main() {
//Rounding gets a bit gross when using floats, at the cost of memory, doubles are used.
string name;
double payRate;
double hours;
double WeeklyWage;
double shoppingPercent;
double entertainmentPercent;
double savingsPercent;
double remainder;
//Program Information
cout << "Name: Summer Job Wage Calculator \n";
cout << "Description: a program that calculates a weekly wage, based on an hourly payrate and how many hours were worked; then calculates amounts for various categories of spending, along with how much of the weekly pay is leftover.\n\n";
//Accept input via cin for hourly wages, pay rate, and name
//getline already in use, no need to change
cout << "What is your full name?: ";
getline(cin, name);
cout << "What is your payrate (per hour)?: ";
cin >> payRate;
cout << "How many hours have you worked?: ";
cin >> hours;
//Get the percentage variables
cout << "\n===NOTE: The following prompts do not need percentage symbols===\n";
cout << "How much would you like to allocate to shopping?\n";
cin >> shoppingPercent;
cout << "How much would you like to allocate to savings?\n";
cin >> savingsPercent;
cout << "How much would you like to allocate to entertainment?\n";
cin >> entertainmentPercent;
//Convert the input to percentages
shoppingPercent = shoppingPercent/100;
entertainmentPercent = entertainmentPercent/100;
savingsPercent = savingsPercent/100;
//Multiply the input to create the WeeklyWage variable
//Possible memory optimization here by removing the WeeklyWage variable, but at the cost of CPU cycles.
WeeklyWage = hours*payRate;
//Remainder will be its own var due to the more complex way to calculate it
remainder = WeeklyWage - WeeklyWage*(shoppingPercent+entertainmentPercent+savingsPercent+tax);
//have a bunch of cout statements that do all the math
// I.e : cout << “Tax: “ << WeeklyWage*tax
cout << fixed << setprecision(2);
cout << setw(15) << "Name:" << right << setw(5+name.length()) << name << endl;
cout << setw(15) << "Wages:" << right << setw(6) << "$" << WeeklyWage*tax << endl;
cout << setw(15) << "shopping:" << right << setw(6) << "$" << WeeklyWage*shoppingPercent << endl;
cout << setw(15) << "entertainment:" << right << setw(6) << "$" << WeeklyWage*entertainmentPercent << endl;
cout << setw(15) << "savings:" << right << setw(6) << "$" << WeeklyWage*savingsPercent << endl;
cout << setw(15) << "remainder:" << right << setw(6) << "$" << remainder << endl;
return 0;
}
/*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
|