+ 1

How to use for loop

So I have to use a for loop in a situation where a guy gets paid a const amount per hour, for 3 weeks And the program should calc the total income during the loop

6th May 2020, 11:56 PM
Maanda Makushu
Maanda Makushu - avatar
2 Answers
+ 2
Hey you don't need a for loop for that :)) int money; cin>>money; int totalHours = 3 * 7 * 24; int totalMoney = money * totalHours; cout << totalMoney;
7th May 2020, 12:07 AM
Arb
Arb - avatar
0
A loop is used for executing a block of statements repeatedly until a particular condition is satisfied. For example, when you are displaying number from 1 to 100 you may want set the value of a variable to 1 and display it 100 times, increasing its value by 1 on each loop iteration. for(initialization; condition ; increment/decrement) { C++ statement(s); } First step: In for loop, initialization happens first and only once, which means that the initialization part of for loop only executes once. Second step: Condition in for loop is evaluated on each loop iteration, if the condition is true then the statements inside for for loop body gets executed. Once the condition returns false, the statements in for loop does not execute and the control gets transferred to the next statement in the program after for loop. Third step: After every execution of for loop’s body, the increment/decrement part of for loop executes that updates the loop counter. Fourth step: After third step, condition is re-evaluated.
7th May 2020, 4:42 AM
ê§àŒ’â˜ŹBad☏Boyâ˜ŹàŒ’ê§‚
ê§àŒ’â˜ŹBad☏Boyâ˜ŹàŒ’ê§‚ - avatar