d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > C++ Issue > Table/ Accumlator
Add Reply New Topic New Poll
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


Thank you in advance
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 😭
}
Trade Moderator
Posts: 26,725
Joined: Dec 20 2005
Gold: 82,500.00
Trader: Trusted
Oct 2 2019 04:54am
What you actually trying to achieve here?
a program that calculate the amount of pay needed?
Member
Posts: 52,271
Joined: Feb 12 2009
Gold: 56.30
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
Trade Moderator
Posts: 26,725
Joined: Dec 20 2005
Gold: 82,500.00
Trader: Trusted
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.
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
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


Thank you in advance


If this is C++17: https://en.cppreference.com/w/cpp/algorithm/accumulate

Native support for parallel processing.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll