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.
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
|
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(1);
srand(time(0));
float salary = 0, bonus = 0, totalpay = 0;
int days = 0;
salary = rand() % 6 + 1;
salary = salary / 100;
days = rand() % 31;
totalpay = salary;
cout << "Starting salary: " << salary << endl
<< "Days worked: " << days << endl
<< "************************************" << endl
<< setw(30) << "Daily Salary" << setw(30) << "Amount Earned" << setw(30) << endl;
for (int d = 0; d < days; d++)
{
if ((d+1) % 5 == 0)
bonus = salary * 10;
else
bonus = 0.00;
cout << d + 1 << '\t'
<< fixed << setprecision(2) << setw(18) << salary *=2 << '\t'
<< (totalpay+bonus) << setw(18) << endl;
totalpay += salary;
}
return 0;
}
|
Made a new topic for this and decided to rewrite the code into something that is more organized. I am getting the error now
invalid operands of types 'int' and 'float' to binary 'operator<<'