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;
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;
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.