This is my assignment, the goal is to look like this but with 30 days:
Starting salary: 0.05
Number of days to work: 5
Day 1: 0.05
Day 2: 0.10
Day 3: 0.20
Day 4: 0.40
Day 5: 0.80
You made $2.05 and earned 1 bonus of $0.50
For this assignment, write a program that will calculate how much a person would earn over a finite (random) period of time if his/her salary is a random amount for the first day and continues to double each day.
So if a person's starting salary is $0.04, they would earn that $0.04 for the first day of work, $0.08 for the second day of work, $0.16 for the third day of work, etc.... Over three days, the person would earn $0.28.
If the example is carried on for a few more days, the person would earn $0.32 for the fourth day, a total of $1.04 ($0.64 in salary and a $0.40 bonus) for the fifth day, and $1.28 for the sixth day, resulting in a total of $2.92 for 6 days of work.
The modulo (%) operates on integers. Do not compute the salary as double or dollars ($). Use unsignedlonglong salary that is in cents. You can then, at end, divide the cents with 100.0 to show dollars.
What is "bonus"?
What is the allowed range of starting salary?
What is the allowed range of days? (you say 30, but your code says 0..5)
I have gotten the code correctly for the starting salary and number of days to work both being random as intended but how would I get it to break down into lists based on days worked?
A waste of time, space and trouble in most cases and that's why you don't see it much. The purists will probably be more condemnatory and express shock/horror at the mere thought of using it.
Maybe it has some use but not much. You don't need it here. :)
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
usingnamespace std;
int main()
{
srand(1);
srand(time(0));
double salary, bonuses, basepay;
int Day, bearned, total; // delcaring intergers
Day = rand() % 30; // randomizing days
basepay >= 1; // making sure basepay isn't less then 1
basepay = rand() % 6; //basepay randomized but never more then 6
basepay = basepay / 100; //basepay divided by 100 to get 0.01
cout << "Starting basepay : " << basepay << endl
<< "Number of days to work: " << Day << endl //displaying the basepay and day
<< "*************************************************" << endl
<< setw(42)<< "Daily Salary" << setw(30)<< "Amount Earned" << endl; //formatting
for (int d = 1; d <= Day; d++) //beginning my loop, d representing day which is less then or equal to the interger of Day and incrementing it by 1 until it reaches the integer Day
{
cout << "Day " << d << '\t' // outputting d
<< fixed << setprecision(2) << setw(30) << salary << '\t' //formatting and displaying the basepay
<< setw(30) << bonuses + salary << endl; //displaying amount earned
salary = basepay *= 2; // Incrementing basepay by *2
if ( (d+1)% 5 == 0)
bonuses = salary * 10;
else
bonuses = 0.00; // if else statement for if theres a bonus or not
}
bearned = Day / 5;
total = bonuses + basepay;
if ( bearned > 1)
cout << endl << "You made " << total << " and earned " << bearned << " bonuses of $" << bonuses;
else
cout << endl << "You made " << total << " and earned " << bearned << " bonus of $" << bonuses; // if else statement to display proper grammar as well as how many bonuses earned
return 0;
}
sometimes I will get all 0s, sometimes I get nothing, sometimes I get incorrect math, can someone help me optimize this? I know it was posted above but I am trying to put it in my own "words" persay. I know its unfinished as well, I still need to display the amount of bonuses earned and total earned and how much the bonuses were and for it to actually display correctly and consistently
In function 'int main()':
18:9: warning: statement has no effect [-Wunused-value]
47:19: warning: 'bonuses' may be used uninitialized in this function [-Wmaybe-uninitialized]
36:30: warning: 'salary' may be used uninitialized in this function [-Wmaybe-uninitialized]
uninitialized == How much is unknown+2 ? Unknown
There are other things, like line 10, that the compiler does not complain about.
Your "bonuses" is either 0 or 10*salary(of the last day).