payment table (for loop)

Hi everyone
I am new to C++ and have problem creating a table of payment ,for 10days max and first day payment 5 doubles every day 5,10,20,40 so on have to use the for loop and no idea how to start
[code]
Pu#include <iostream>
using namespace std;

int main()
{
int Days; // Maximum number to square


cout << "Enter number of Days: ";
cin >> Days;

// Display the table.
cout << "Days Pay\n"
<< "-------------------------\n";

for (int num = Days; num <= ; num++)
cout << num << "\t\t" << (5^num) << endl;

return 0;
Last edited on
If you want it to DOUBLE, then you shouldn't be squaring anything. You'll simply multiply by two.

5^2 = 25

I think you want something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main()
{
int Days; // Maximum number to square
int pay = 5;

cout << "Enter number of Days: ";
cin >> Days;

// Display the table.
cout << "Days Pay\n"
<< "-------------------------\n";

cout << '0' << "\t\t" << (pay) << endl; //Day 1

for (int num = 1; num < days; num++)
cout << num << "\t\t" << (pay*=pay) << endl;

return 0;
Last edited on
Just to spell it out: ^ does not mean "exponentiation" in C++, it means XOR.
Repeated multiplication or std::pow is used for raising numbers to powers.
You don't want exponentiation at all.

Just multiply by 2
pay *= 2;
or simply:
pay += pay;
Thank you all ,pay+=pay worked for me:)
but days start from 0 not 1
days
0
1
2
3
4
5
int Days=1; but still start from 0
Last edited on
@rad48

You should tweak the code as needed. The change from starting at 1 instead of 0 is very minor.
1
2
3
4
pay = 5;
cout << '0' << "\t\t" << pay << endl;
for (int num = 1; num < days; num++)
  cout << num << "\t\t" << (pay *= pay) << endl;

is same as
1
2
3
4
5
pay = 5;
cout << '0' << "\t\t" << pay << endl;
for (int num = 1; num < days; num++) {
  cout << num << "\t\t" << (pay *= pay) << endl;
}

is same as
1
2
3
4
5
6
pay = 5;
cout << '0' << "\t\t" << pay << endl;
for (int num = 1; num < days; num++) {
  pay *= pay;
  cout << num << "\t\t" << pay << endl;
}

is almost same as
1
2
3
4
5
pay = 5;
for (int num = 0; num < days; num++) {
  cout << num << "\t\t" << pay << endl;
  pay *= pay;
}

Topic archived. No new replies allowed.