Penny Program

Ok so this is a loop that shows how many pennies a person will have everyday for a total of 64 days. My teacher wants me to also put in two asterisk symbols (**) next to the day that the amount of money equals 1 million dollars. I'm not really sure how to do that.

Any hints or suggestions?

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
  #include <iostream>
#include <cmath>
#include <fstream>
#include <iomanip>
using namespace std;

int main ()
{

 ofstream outputFile;
 outputFile.open ("pa04-output.txt");

 int days;
 double sum = 0;
 double total;


outputFile << "Days         Pennies                total\n";
outputFile << "------------------------------------------\n";

 for (days = 1; days <= 64; days++) {
 outputFile << setw(3) <<  days;
 sum =  pow(2, days) - 1;
 outputFile << setw(20) << sum;
 total = sum * 0.01;
 outputFile << setw(20) << total << endl;
 }


return 0;
}



Then you will have to compute the sum and total first.
There is no exact one million in your data so i took the range of 1 million.

1
2
3
4
5
6
7
8
9
10
11
for(days = 1; days <= 64; days++)
{
    sum = pow(2,days) - 1;
    total = sum * 0.01;

    outputFile<<setw(3)<< days;
    if(total > 999999 && total < 1999999) 
        outputFile<<" **";  
    outputFile<<setw(20)<<sum;
    outputFile<<setw(20)<<total<<endl;
}
yea i was noticing that to so i was kind of confused. last question i have is my answers display in exponents when they start getting really big not sure how to fix it i tried using long double and the last numbers had a negative result i forgot how to fix this.
1
2
outputFile fixed<< setw(30) << sum;   //set width to 30 to make it neat
outputFile fixed<< setw(30) << total << endl;
Topic archived. No new replies allowed.