d2jsp Forums > Off-Topic > Programmer's Haven > C/C++/C# > C++ Issue > Table/ Accumlator
slapyourDog
Group: Member
Posts: 644
Joined: Feb 20 2015
Gold: 79.00
Sep 28 2019 06:38pm
int day;
int workdays;

std::cout << "Total days of work\n";
std::cin >> workdays;

std::cout << "\days pay\n";
std::cout << "=========\n";

for (day = 1; day <= workdays; day++);
std::cout << day << "\t\t" << (day * .200000) << std::endl;

I basically type in my total day which is 5 and my table goes to six instead of 1-5

I also am trying to get an accumulator statement to add up the tables outputs

slapyourDog
Group: Member
Posts: 644
Joined: Feb 20 2015
Gold: 79.00
Sep 28 2019 07:18pm

int workdays = 1, r;

unsigned long pay = 1, n, Sum = 1;

std::cout << "\nEnter the No. of days you will be working? = "; std::cin >> workdays;

std::cout << "\n\nDay\t\tPay";

std::cout << "\n-----------------------------";

for (r = 0; r < workdays; r++)

{

n = r;
pay = pow(2, n);

Sum =Sum + pay;

std::cout << "\n" << (r + 1) << "\t\t US \$ " << pay << "\n";

}

std::cout << "\n\nYour total pay is US \$ " << Sum << ".";

Update, now my table wont out put .200000 doubling I can only get it to double 1 😭
}
Yakir
Posts: 26,346
Joined: Dec 20 2005
Gold: 72,220.00
Oct 2 2019 04:54am
What you actually trying to achieve here?
a program that calculate the amount of pay needed?
bodierox
Group: Member
Posts: 51,598
Joined: Feb 12 2009
Gold: 10.50
Oct 4 2019 10:02am
It is most likey because you're starting at 1 instead of 0.
Remember in most programming that the iteration or variable should start at 0.

This post was edited by bodierox on Oct 4 2019 10:02am
Yakir
Posts: 26,346
Joined: Dec 20 2005
Gold: 72,220.00
Oct 4 2019 12:33pm
Quote (bodierox @ Oct 4 2019 07:02pm)
It is most likey because you're starting at 1 instead of 0.
Remember in most programming that the iteration or variable should start at 0.

0-5 = 5
1<=5 = 5

So it's the same thing as the number of iterations.
I still waiting for him to explain what he actually trying to achieve.
Muted
Group: Member
Posts: 31,674
Joined: Nov 10 2007
Gold: 2.00
Warn: 10%
Oct 22 2019 04:07am
Quote (slapyourDog @ 28 Sep 2019 19:38)
int day;
int workdays;

std::cout << "Total days of work\n";
std::cin >> workdays;

std::cout << "\days pay\n";
std::cout << "=========\n";

for (day = 1; day <= workdays; day++);
std::cout << day << "\t\t" << (day * .200000) << std::endl;

I basically type in my total day which is 5 and my table goes to six instead of 1-5

I also am trying to get an accumulator statement to add up the tables outputs