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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
|
//
#include "stdafx.h"
#include <cmath> //rounding function
#include <iomanip> // setprecision function
#include <algorithm> // transform function
#include <conio.h> // getch() function
#include <string> // string function
#include <iostream>
using namespace std;
double intround(double);
double calcRaiseAmount(double, double);
double calcNewPay(double, double);
void monthlyGross();
void projGross();
void showTitle();
void getName(string &);
void chooseMenu();
int main()
{
double currentpay, annualraises, annualpay, raiserate, raiselength, raiseamount, newpay, weeklyhours, weeklypay;
char start, pay;
int intro = 0;
string name;
if (intro == 0)
{
showTitle();
getName(name);
chooseMenu();
intro = 1;
}
start:
if (intro == 1)
{
cout << "\nEnter current hourly pay.\n";
}
intro = 1;
cin >> currentpay;
cin.ignore(100, '\n');
while (currentpay <= 0)
{
cout << "\nError: Inproper amount.\n";
cout << "Enter current hourly pay.\n";
cin >> currentpay;
cin.ignore(100, '\n');
}
cout << "\nEnter raise percent (decimal format).\n";
cin >> raiserate;
cin.ignore(100, '\n');
while (raiserate < 0)
{
cout << "\nError: Inproper amount";
cout << "\nEnter raise percent (decimal format).\n";
cin >> raiserate;
cin.ignore(100, '\n');
}
raiseamount = calcRaiseAmount(currentpay, raiserate);
newpay = calcNewPay(currentpay, raiserate);
cout << fixed << setprecision(2) << "\nYour raise is " << raiseamount << " per hour.\n";
cout << fixed << setprecision(2) << "\nYour new pay is " << newpay << " per hour.";
cout << "\nEnter your hours per week.\n";
cin >> weeklyhours;
cin.ignore(100, '\n');
while (weeklyhours <= 0)
{
cout << "\nError: Inproper amount.\n";
cout << "Enter your hours per week.\n";
cin >> weeklyhours;
cin.ignore(100, '\n');
}
cout << "\nEnter the amount of hours or weeks it takes you to obtain a raise.\n";
cin >> raiselength;
cin.ignore(100, '\n');
if ((raiselength <= 52)&&(raiselength >=1))
{
annualraises = (52/raiselength);
}
else if ((raiselength > 52)&&(raiselength <=8760))
{
annualraises = ((weeklyhours*52)/raiselength);
}
else if (raiselength == 0)
{
annualraises = 0;
}
while ((raiselength < 0)||(raiselength > 8760))
{
cout << "\nError: Inproper amount.\nEnter the amount of hours or weeks it takes you to obtain a raise.\n";
cin >> raiselength;
cin.ignore(100, '\n');
}
pay:
cout << "\nWould you like to use (C)urrent pay or (N)ew pay?\n";
pay = getch();
switch(toupper(pay))
{
case 'C':
for (;annualraises>1;annualraises--)
{
currentpay = ((currentpay*raiserate)+currentpay);
}
weeklypay = (weeklyhours*currentpay);
annualpay = ((weeklyhours*52)*currentpay);
break;
case 'N':
for (;annualraises>1;annualraises--)
{
newpay = ((newpay*raiserate)+newpay);
}
weeklypay = (weeklyhours*newpay);
annualpay = ((weeklyhours*52)*newpay);
break;
default:
cout << "Input error";
goto pay;
}
cout << fixed << setprecision(2) << "\n" << name << " made " << weeklypay << " dollars this week.";
cout << fixed << setprecision(2) << "\n" << name << " made a total of " << annualpay << " for the year.";
cout << "\nWould you like to continue? (Y)es or (N)o";
start = getch();
switch(toupper(start))
{
case 'Y':
goto start;
break;
}
return 0;
}
void showTitle()
{
cout << "********************\n********************\n********************\n";
cout << "**** WELCOME TO ****\n**** XYRIENE'S ****\n**** PAY CHART ****\n";
cout << "********************\n********************\n********************\n\n";
}
void chooseMenu()
{
char choice;
choice:
cout << "What would you like to do?\n";
cout << "(H)ourly gross, (M)onthly gross, (P)rojected gross\n";
choice = getch();
switch(toupper(choice))
{
case 'M':
monthlyGross();
break;
case 'P':
projGross();
break;
default:
cout << "Error: Invalid input";
goto choice;
break;
}
}
void getName(string &user)
{
cout << "Name: ";
getline(cin, user, '\n');
transform(user.begin(), user.end(), user.begin(), tolower);
}
double intround(double r) {
return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
}
double calcRaiseAmount(double currentpay, double raiserate)
{
return (currentpay*raiserate);
}
double calcNewPay(double currentpay, double raiserate)
{
return (calcRaiseAmount(currentpay, raiserate) + currentpay);
}
void monthlyGross()
{
int x, y, intro = 0;
string months[12] = {"Janurary", "Feburary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
double income[12] = {}, avgIncome, totlIncome;
double percent[12] = {};
cout << "\n\nEnter your income for the following months.\n";
for (x=0;x<12;x++)
{
cout << months[x] << ": ";
cin >> income[x];
cin.ignore(100, '\n');
}
x=0;
y=1;
for(x=0;y<12;x++)
{
if (income[x] > income[y])
{
percent[x] = (1-(income[y]/income[x]));
cout << fixed << setprecision(2) << months[x] << "-" << months[y] << " you had a " << percent[x]*100 << "% decrease. ";
}
if (income[x] < income[y])
{
percent[x] = (income[y]/income[x]);
cout << fixed << setprecision(2) << months[x] << "-" << months[y] << " you had a " << percent[x]*100 << "% increase. ";
}
if (income[x] == income[y])
{
percent[x] = 0;
cout << fixed << setprecision(2) << months[x] << "-" << months[y] << " you had a " << percent[x]*100 << "% increase. ";
}
y = (y+1);
}
totlIncome = (income[0]+income[1]+income[2]+income[3]+income[4]+income[5]+income[6]+income[7]+income[8]+income[9]+income[10]+income[11]);
avgIncome = (totlIncome/12);
cout << fixed << setprecision(2) << "\n\nYour average monthly income is $" << avgIncome << ". \n";
cout << fixed << setprecision(2) << "Your total annual income is $" << totlIncome << ".";
int main();
}
void projGross()
{
int x, y = 0;
double incomes[12][3] = {};
string months[12] = {"Janurary", "Feburary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
cout << "\nEnter your current income and your projected income for each month.\n";
for (x = 0; x < 12; x++)
{
y = y++;
cout << months[x] << ": ";
cin >> incomes[x][0];
cin >> incomes[x][1];
}
for (x = 0; x < 12; x++)
{
if (incomes[x][0] > incomes[x][1])
{
incomes[x][2] = ((incomes[x][1]/incomes[x][0])*100);
cout << fixed << setprecision(2) << "\nYou have met your goal for the month of " << months[x] << " by " << incomes[x][2] << "%.\n";
}
if (incomes[x][0] < incomes[x][1])
{
incomes[x][2] = ((1-(incomes[x][0]/incomes[x][1]))*100);
cout << fixed << setprecision(2) << "\nYou have not yet met your goal for the month of " << months[x] << " by " << incomes[x][2] << "%.\n";
}
if (incomes[x][0] == incomes[x][1])
{
incomes[x][2] = 100;
cout << fixed << setprecision(2) << "\nYou have met your goal for the month of " << months[x] << " by " << incomes[x][2] << "%.\n";
}
}
int main();
}
|