For Loop

Printable View

• 02-07-2002
learnin2program
For Loop
I am trying to create a program that allows a user to enter the input amount (ex. .01)

Day Input Total
1 .01 .01
2 .02 .03
3 .04 .07

The input amount needs to be doubled each day and the total needs to be displayed...

Any suggestions would be appreciated
• 02-07-2002
Nor
Not to be rude but I sugesthttp://www.cprogramming.com/tutorial.html
• 02-07-2002
swoopy
I guess to input the amount, use either a double or float.

double amount;
cin >> amount;

Or you could have him enter cents and use an integer. Then when you print it out, use the modulus operator (%) to get dollars and cents.

int amount;
cin >> amount;
dollars = amount / 100;
cents = amount % 100;
cout << dollars << "." << cents << endl;

However, the integer may eventually overflow, after you double it numerous times.
• 02-08-2002
Unregistered
double amount;
double total = 0.00;
int days;
int i;

enter amount to start with:

enter number of days to calclulate:

total = amount;
cout day 1 amount total;

for i = 2 i < days, i++
amount *= 2
total += amount
cout day i amount total
• 02-08-2002
swarm
than again he was asking that the totals have to be doubled, not use a double.