repost: still stuggling w/for loop
Hello... I am working on a For Loop Problem.. I have tried modifying it in many ways for it to work - but it still doesn't ... any help would be appreciated..
The problem: To make a For Loop that asks for an initial amount input.. ex. $.01. It will double that amount every day for 30 days... 3 columns need to be displayed - the day - the input - the total...
ex. day input total
1 .01 .01
2 .02 .03
3 .04 .07
4 .08 .15 etc...
This is the code I have so far:
#include<iostream.h>
#include<math.h>
main()
{
double daynumber, amountentered=0, depositamount = 0, totalbal = 0, numberofday\
s;
int maxnumberofdays = 30;
cout<<"Please enter input amount"; cin>>amountentered;
cout<<"Day\tDeposit\tTotal\n";
for(numberofdays = 1; numberofdays<=maxnumberofdays; numberofdays++)
double amountentered = depositamount; // making the deposit amount the sames\
as amount entered
depositamount = (2*depositamount);
cout<<numberofdays<<"\t"; cout<<depositamount<<"\t";
cout<<totalbal<<"\t";
amountentered += amountentered;
return 0;
}
When I run the program it asks for the input amount... if I put in .01 as an example the output is:
Day Deposit Total
31 0 0
Any help would be appreciated...
[email protected]
try this, and let me know if it works
int main( )
{
int day = 0, input = 0, total = 0;
cout << "Enter daily value" << endl;
cin >> input;
for( ; day < 30; day++ )
{
cout << "Day: " << day+1;
cout << "Input: " << input;
cout << "Total: " << (total+=input);
input *= 2.0;
}
}
repost: still stuggling with for loop
I tried the suggestion and modified the code a little to make it more readable... The code I tried was:
#include<iostream.h>
#include<math.h>
int main( )
{
int day = 0, input = 0, total = 0;
cout << "Enter daily value" << endl;
cin >> input;
for( ; day < 30; day++ )
{
cout << day+1<<"\t";
cout << input<<"\t";
cout << (total+=input)<<"\t\n";
input *= 2.0;
}
}
The output was
Day Input Total
1 0 0
2 0 0
3 0 0
4 0 0
etc
Any other suggestions would be appreciated