Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is an array declaration containing income values for seven years consecutiv

ID: 3583499 • Letter: H

Question

Here is an array declaration containing income values for seven years consecutively: Write is the value of variable: years Write down code section to add up the total income with a for loop and the loop terminated with array method length and display O/P in this format: Total income: End of Report Write down the O/P after the for loop If you declare the array index variable within the for loop, after the loop, could you print out the value of the array index? double[] income = {50000.25, 52000.50, 54000,00}; double total; in years = income length;

Explanation / Answer

Ans.1. Since income contains 3 elements, therefore years = 3

Ans.2. double total = 0;
   for (int i = 0; i < income.length; i++)
{
total += income[i];
}
   cout << "Total income: $" << total << endl;
cout << "End of Report" << endl;

Ans.3. Total income: $156000.75
End of Report

Ans.4. No, because the variable is declared within the scope of for loop. Once, the for loop gets executed, the index variable is no longer in the scope.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote