I am writing a program for class were the user earns 1 for the first day of work and 2 pennies on the second and 4 pennies on the 3 day doubling every day after that. My problem is, is that I can't figure out how to make the program double i tried using the pow function but that did work. Help please.
Well, unless I misunderstood the question, dailyPay=1 seems sensible, then each day, the value of dailyPay needs to be multiplied by 2, for example dailyPay *= 2;
Well, I tend to give hints rather than complete answers, because I feel the best way to learn is to try to figure things out for yourself. Can you show the updated version of the code please.
I can get it to count the days my problem is getting it to double the pennies each I am not quit sure how to go about that it should go 1, 2, 4, 8, 16, 32 ....
I am not understanding where it should be placed. Everywhere I have tried to add it or replace something with it I get errors. And no matter where i try it i get this error 1 IntelliSense: operand of '*' must be a pointer.
here's my new code so far. Its getting better but its still not right it counts my days correctly but my income looks like this
1, 2, 12, 573, 1.65888e+006 instead of 1, 2, 4, 8, 16, 32......
int main()
{
double days, dailyPay=1, day, pennies = 1;
cout << "How many days has the employee worked this month?: ";
cin >> days;
1.)Declare and define a constant variable named "days", or have the user input a number.
2.)Define two variables which hold the current amount of pennies, and the number of pennies you earn each day. Some possible names are "pennies" and "profit".
3.)Initialize profit to 1.
4.)Write a for loop, which does the following while a counter is less than "days".
it has to display only that days pay like on day 1 it will say 1 on day 2 the pay is 2 on day three the pay 4 and the pay doubles each day. But you have to display each days pay. it counts my days. My problem is in squaring the pennies each day but if you square 1 the answer is 1 I can't get it to double it for each day. Nothing I am trying is working.
I've a feeling you're missing something very straightforward here. The idea of squaring a number is pretty much off-topic and not needed here. Instead of squaring 1
1 * 1 = 1
just multiply 1 by 2
1 * 2 = 2
on the next day, multiply the previous value by 2
2 * 2 = 4
and the day after that, multiply the previous value by 2
4 * 2 = 8
and the day after that, ...
When I use the pow function it always starts with 2 I need the pay to start with 1. then 2,4,8.....
I have tried to plug it in different ways and have even changed it around changed numbers tried to set pennies equal to one( when I do all days keep one. i still have no clue as to how to make this work.
Forget the power function completely. It does not need to be used in this program.
Now, think of it in the real world.
1. First day, you start with one.
2. Second day, the one you have doubles into 2 (you multiplied your current pay by two
3. Third day, the two doubles (you multiplied your current pay by two)
4. Fourth day, the four doubles (you multiplied your current pay by two)
Sense a pattern?
*cough* You multiply your current pay by two each time *cough*
Now, fit this in a for loop and output it each time and you are done.