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

Part C: Create the following loop The following loop should be implemented as se

ID: 3844035 • Letter: P

Question

Part C: Create the following loop The following loop should be implemented as separate program. The name of the source file for Task 4 is loopset4.cpp Loop 1: Any loop Type using integer values Write a program that prompts for the following: Start Number: Ending Number: Steps: Make sure Ending Number is greater than or equal to the Starting Number and the Steps is greater than or equal to one. If not the program should loop until these conditions are met. Determines using any type of loop from Start to End in increments of "Steps" from above: Sum of ODD NUMBERS Sum of EVEN Numbers Total Sum of All Numbers Average of the Sum of All Numbers

Explanation / Answer

/* Loop1 question*/

#include<iostream>
using namespace std;

int main()
{
   int start, end,steps, i,sum_odd=0,sum_even=0,sum_tot=0;
   int count=0;   //to count the numbers
   float avg;
   do {
  
   cout<<"Enter Start number: ";
   cin>>start;
   cout<<"Enter end number: ";
   cin>>end;
   cout<<"Steps: ";
   cin>>steps;
   }while(start>end && steps<1);   //statement to satisfy all the conditions
  
   for(i=start;i<=end;i+=steps)   //using for loop from start to end with increments of 'steps'
   {  
       count++;
       sum_tot+=i;   ///calculating the total sum by adding each number
       if(i%2==0)
           sum_even+=i;   //calculating even sum
       else
           sum_odd+=i;   //calculating odd sum
   }
   avg = sum_tot/count;
   cout<<" Sum of even numbers is: "<<sum_even;
   cout<<" Sum of odd numbers is: "<<sum_odd;
   cout<<" Sum of all numbers is: "<<sum_tot;
   cout<<" Average of all numbers is: "<<avg;
    return 0l;
}

/*Part C*/

#include<iostream>
using namespace std;

int main()
{
   int start,end,i,steps;
   cout<<"Start: ";
   cin>>start;
   cout<<"End: ";
   cin>>end;
   cout<<"Steps: ";
   cin>>steps;
   for(i=start;i<=end;i+=steps)
   {   cout<<i<<"-";
       if(i%2==0)
       {   cout<<" even";
           if(i%3==0)
               cout<<", three";
           if(i%5==0)
               cout<<", five";
       }

       else
       {
           cout<<" odd";
           if(i%3==0)
               cout<<", three";
           if(i%5==0)
               cout<<", five";
          
       }
       cout<<endl;
   }
  
}

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